rough notes until i turn this into a proper doc __ __ | |--.---.-.----.| |--.--.--.-----. | _ | _ | __|| <| | | _ | |_____|___._|____||__|__|_____| __| |__| assumptions =========== - you have setup a smb volume on your nas that the pies will mount set up flow =========== - set up smb credentials on root for pi - mount nas smb volume - set up back up script bonus setup: off site backup set up smb ========== ``` cat .smbcredentials_sharename username=CHANGE_ME password=CHANGE_ME domain=CHANGE_ME (default is WORKGROUP) # TODO: add to /etc/fstab for auto mounting sudo mount -t cifs \ //NAS_HOSTNAME/BACKUP_VOLUME \ /mnt/nas \ -o credentials=/root/.smbcredentials_sharename ``` backup script ============= tip: store the script on the nas, that way you can only run it if the mount is available. backup-pi.sh - back up home drives on raspberry pies ``` #! /bin/bash -f target_host=$(hostname) nas_host="CHANGE_ME" if [ "$target_host" = "$nas_host" ]; then echo "This script should not be run on $nas_host see README" exit 1 fi scripts_dir="/mnt/nas/Backups/raspberry_pies" target_directory="$scripts_dir/$(hostname)" log_file="$scripts_dir/rsync-home-drives.$target_host.$(date +%a).log" exclusions_file="$scripts_dir/backup-homes-exclusions.txt" if [[ ! -d "$target_directory" ]]; then echo "creating $target_directory..." mkdir -p "$target_directory" fi rsync -havP --stats --no-links --no-perms --no-owner --no-group \ --log-file="$log_file" \ --exclude-from="$exclusions_file" \ --delete-excluded \ /home $target_directory ``` schedule back up ================ ``` # https://www.loggly.com/ultimate-guide/using-journalctl/ # source: https://askubuntu.com/questions/222512/cron-info-no-mta-installed-discarding-output-error-in-the-syslog # for script output when cron sudo apt-get install postfix # alternatively # 0 3 * * * (cmd1; cmd2) 2>&1 | logger -t mycmd sudo crontab -l @daily /mnt/nas/Backups/raspberry_pies/backup-pi.sh # if using logger: grep 'mycmd' /var/log/syslog journalctl --unit cron.service --since "1 days ago" ``` checking cron for data ``` journalctl --unit cron.service --since "1 days ago" ```