diff --git a/README.md b/README.md index 12092b8..bcad423 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ A set of bash scripts for managing backups. ## Overview -Bashup includes scripts for backing up & restoring Files/Directories, MySQL databases, and PowerDNS zones. +Bashup includes scripts for backing up and restoring Files & Directories, MySQL/MariaDB databases, and PowerDNS zones. The scripts assume a mountable backup disk (cloud based block storage, NFS mount, dedicated local partion, etc.) but work equally well with a local backup directory. If the backup dir is configured in /etc/fstab as a mountable disk then it will automatically be mounted and then unmounted when the scripts run. For "files" backups a combination of rsync & hard links is used. This conserves space as files that are unchanged simply reference the same indode instead of having duplicate files. -It is intended that each of the desired "backup" scripts is run once a day via cron. The scripts can be re-run multiple times in one day without any negative repercussions. If an existing backup already exists it is simply skipped, it is not overwritten with a newer copy. +The systemd timer runs the desired "backup" scripts once per day. The scripts can also be run manually. They can be re-run multiple times in one day without any negative repercussions. If an existing backup already exists it is simply skipped, it is not overwritten with a newer copy. The "restore" scripts can be run interatively. If you do not specify options for the restore then you will be prompted with menus of options to help you select what to restore. If the appropriate options are specified on the command line then the restore will be completed without prompts. @@ -21,19 +21,21 @@ Built and tested on Ubuntu 20.04 these scripts should run fine on any current De Create a backup directory or mount. For example, make a directory named /mnt/backups, create an NFS mount for that directory, and configure it in /etc/fstab. Include the "noauto" option in fstab so that it is not automatically mounted, the scripts will take care of mounting the device as needed. ```bash +# download and install the bashup scripts cd /usr/local/src/ wget https://git.stack-source.com/msb/bashup/archive/master.tar.gz -O bashup.tar.gz tar zxvf bashup.tar.gz cd bashup -cp bashup*.sh /usr/local/sbin/ +cp sbin/bashup*.sh /usr/local/sbin/ chmod 755 /usr/local/sbin/bashup*.sh chown root:root /usr/local/sbin/bashup*.sh +# install & enable bashup systemd cron +cp systemd/bashup-cron.* /usr/lib/systemd/system/ +chmod 644 /usr/lib/systemd/system/bashup-cron.* +systemctl enable bashup-cron.timer +systemctl start bashup-cron.timer +# customize configuration nano /usr/local/etc/bashup.conf -crontab -e ``` The "nano /usr/local/etc/bashup.conf" command is optional. Do this if you need to override any of the default configurable settings found at the top of the /usr/local/sbin/bashup.sh script. - -For the crontab add an entry for each of the "backup" scripts that you'd like to run. For example, to back up files at 3:01 am every day add this crontab: - -`1 3 * * * /usr/local/sbin/bashup-backup-files.sh` diff --git a/sbin/bashup.sh b/sbin/bashup.sh index 8535914..bea2cb1 100755 --- a/sbin/bashup.sh +++ b/sbin/bashup.sh @@ -15,6 +15,9 @@ retention_days=7; # backup storage directory backup_storage_dir='/mnt/backups'; +# which backup scripts to run via bashup-cron.sh - options are 'files', 'mysql', 'pdns' +bashup_jobs=('files' 'mysql'); + # directories to be backed up by files backup_dirs=('/etc' '/home' '/root' '/srv' '/usr/local' '/var/www'); diff --git a/systemd/bashup-cron.timer b/systemd/bashup-cron.timer index d32f0b8..c15c7d9 100644 --- a/systemd/bashup-cron.timer +++ b/systemd/bashup-cron.timer @@ -6,8 +6,8 @@ Description=Bashup cron for automatic backups [Timer] -# Run daily between 3-5 am -OnCalendar=*-*-* 03:00:00 +# Run daily at a random time between 2:00 and 4:00 am +OnCalendar=*-*-* 02:00:00 RandomizedDelaySec=7200 Unit=bashup-cron.service