#!/bin/bash # Cronjob needs to be on one line, spaced out for example/ in-case running cronjob from a script that just runs the below # e.g. 0 0 * * * /home/nathan/backupScripts/docker_backup.sh \ # -c "duckdns homer" \ # -d /home/samba/share/Docker_prod \ # -b /home/nathan/testBack \ # -r pi2 \ # -R ~/backups/pi1/docker while getopts d:b:r:R: flag do case "${flag}" in d) DIR=${OPTARG};; # Directory to backup b) BACKUP_DIR=${OPTARG};; # Where the backup is on local host r) REMOTE=${OPTARG};; # user@remote or alias (from SSH config), prefer to use alias, as it can deal with port differences R) REMOTE_DIR=${OPTARG};; # Location of remote backup i.e. /backup/borg/HOSTNAME/docker (then /npm, /vaultwarden, etc.) esac done # /var/spool/cron/crontabs # Cron backup # LOCAL export BORG_REPO=$BACKUP_DIR borg create ::{hostname}-{now} $DIR #rdiff-backup $DIR/$i $BACKUP_DIR/$i # If a directory doesn't exist, it get created too # Keep last 24 hours of backups, 7 daily backups (one a day/week), 4 weekly (one a week for a month), and 6 monthly, and 1 a year borg prune \ --glob-archives '{hostname}-*' \ --keep-hourly 24 \ --keep-daily 7 \ --keep-weekly 4 # Create the remote directory for backup if it doesn't exist ssh $REMOTE mkdir -p $REMOTE_DIR rsync -azh -e ssh \ --delete \ $BACKUP_DIR \ $REMOTE:$REMOTE_DIR