Bash script to backup multiple folders and to clean up old backups based on a retention time. Features configurable post/pre-commands, tar excludes as well as backup retentions. Original script from https://github.com/frdmn/tar-multibackup.
cd /usr/local/src
git clone https://github.com/SysSU/multibackup-with-rclone.git
ln -sf /usr/local/src/tar-multibackup/multibackup /usr/local/bin/multibackup
cp /usr/local/src/tar-multibackup/multibackup.conf ~/.multibackup.conf
timestamp
= Format of the timestamp, used in the backup target filenamebackup_destination
= Local directory which is used to store the archives/backupsrclone_destination
= Rclone remote and path where archives/backups will be copied torclone_config
= Specify Rclone config file locationfolders_to_backup
= Array of folders to backupbackup_retention
= Retention time how long we should keep the backupspre_commands
= Array of commands that are executed before the backup starts (stop specific service)post_commands
= Array of commands that are executed after the backup finished (start specific service)ping_host
= URL or host you want to "ping" at end of backup using curl. You can use services like healthchecks.io
DEBUG
= if set to "true",set -x
will be setCONFIG
= if you want to use a different configuration file than the
Example:
CONFIG=/tmp/testbackup.conf DEBUG=true multibackup
vi ~/.multibackup.conf
# Timestamp format, used in the backup target filename
timestamp=$(date +%Y%m%d)
# Destination where you want to store your backups
backup_destination="/var/backups"
# Folders to backup
folders_to_backup=(
"/etc"
"/var/mail"
"/var/www"
)
# Files and folders that are excluded in the tar command
tar_excludes=()
# How long to you want to keep your backups (in days)
backup_retention="+7"
# Commands that are executed before the backup started
pre_commands=()
# Commands that are executed after the backup is completed
post_commands=()
To make sure the backup is executed automatically and recurring, we're going to add a simple cronjob:
vi /etc/cron.d/backup-liveconfig
#
# cronjob to backup LiveConfig, daily at 5:00 am
#
0 5 * * * root /usr/local/bin/multibackup &>/dev/null