This is a Taskfile to backup files, directories, MySQL and MongoDB databases to a remote storage like Google Drive, GCS and S3.
It uses 7z to compress the files and rclone to upload them to a remote storage.
It supports multiple backup profiles and can be easily extended.
Install Taskfile, 7z and rclone on your machine.
Create a profile for rclone and configure it to use a remote storage like Google Drive, GCS and S3.
Create a .env.<profile> file in the same directory as the Taskfile and add overrides for the environment variables defined in the .env.dist.
Run PROFILE=<profile> task backup to backup according to the profile.
The configuration is done using environment variables. The following environment variables are supported:
BACKUP_WORK_DIRECTORY: The directory to operate in. Default:/tmp/backupCOMPRESSION_7Z_PATH: The path to the7zexecutable. Default:/usr/bin/7zCOMPRESSION_LEVEL: The compression level to use. Default:5COMPRESSION_PASSWORD: The password to use for the compression. Default: ""BACKUP_INCLUDE_DIRS: The directories to include in the backup. Enter the directories separated by a comma. Example:/var/www/dir1,/var/www/dir2BACKUP_EXCLUDE_DIRS: The directories to exclude from the backup. Enter the directories separated by a comma. Example:dir1/vendor,/var/www/dir2/sensitive/dataMYSQL_USERNAME: The username to use to connect to the MySQL database.MYSQL_PASSWORD: The password to use to connect to the MySQL database.MYSQL_DATABASES: The databases to backup. Enter the databases separated by a comma. Example:db1,db2MONGODB_USERNAME: The username to use to connect to the MongoDB database.MONGODB_PASSWORD: The password to use to connect to the MongoDB database.MONGODB_AUTH_DB: The authentication database to use.MONGODB_DATABASES: The databases to backup. Enter the databases separated by a comma. Example:db1,db2RCLONE_PATH: The path to thercloneexecutable. Default:/usr/bin/rcloneRCLONE_CONFIG_PATH: The path to thercloneconfiguration file. Default:~/.config/rclone/rclone.confRCLONE_REMOTE: The profile to use forrclone. Example:gdriveRCLONE_DESTINATION: The destination to use forrclone. Example:/BACKUP_RETENTION: The retention policy to use. Example:15d
The MySQL backup is done using the mysqldump command.
Make sure to create a user with the necessary permissions to backup the databases.
CREATE USER 'backup'@'localhost' IDENTIFIED BY 'password';
GRANT SELECT ON 'db1'.* TO 'backup'@'localhost'; # You might need to grant more permissions depending on your use case
FLUSH PRIVILEGES;The MongoDB backup is done using the mongodump command.
Make sure to create a user with the necessary permissions to backup the databases.
use db1;
db.createUser({user: "backup", pwd: "password", roles: ["read"]});Run PROFILE=<profile> task backup to backup your files.
Set cron jobs to run the backup at regular intervals.
0 0 * * * cd /root/backup && PROFILE=<profile> task backupThis project is licensed under the MIT License - see the LICENSE file for details.