-
-
Save mcxiaoke/bca0e5ed7b4fa83a5ebc329deba68abf to your computer and use it in GitHub Desktop.
Revisions
-
ryankurte revised this gist
Mar 18, 2020 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,4 +11,9 @@ cp backup.env backup.exclude /etc/ cp backup.service backup.timer /etc/systemd/system # Install backup service systemctl enable backup.service systemctl enable backup.timer # Start timer systemctl start backup.timer -
ryankurte revised this gist
Mar 18, 2020 . 4 changed files with 30 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,9 @@ RESTIC_REPOSITORY=/media/large1/backups/restic # Restic password file RESTIC_PASSWORD_FILE=/root/.restic.pass # Exclude file for rsync --exclude-from EXCLUDE_FILE=/etc/backup.exclude # Directories to back up BACKUP_DIRS="/home;/etc" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ .cargo/registry .toolchain target go/pkg go/src .cache .mozilla This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,6 @@ # Place in /usr/sbin/backup.sh # Enable with `systemctl enable backup.timer` # Check status with `systemctl status backup.service` set -e # Check variables @@ -27,12 +26,14 @@ if [ -Z "$BACKUP_DIRS" ]; then exit 1 fi if [! -Z "$EXCLUDE_FILE" ]; then EXCLUDES="--exclude-from=$EXCLUDE_FILE" fi # Split dirs using semicolons DIRS=$(echo $BACKUP_DIRS | tr ";" "\n") function do_rsync() { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ #!/bin/bash # Helper script to install the backup service # Copy tool cp backup.sh /usr/sbin/ # Copy configuration cp backup.env backup.exclude /etc/ # Copy units cp backup.service backup.timer /etc/systemd/system # Install backup service systemctl enable backup.timer -
ryankurte revised this gist
Mar 18, 2020 . 3 changed files with 53 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ # Systemd environment file for backup.sh daily backup service # Place in /etc/backup.env # Destination for rsync file system clone BACKUP_DEST=/media/large1/backups/raw # Destination for restic repository RESTIC_REPOSITORY=/media/large1/backups/restic # Restic password file RESTIC_PASSWORD_FILE=/root/.restic.pass # Directories to back up BACKUP_DIRS="/home;/etc" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,12 @@ Description=Daily backup service [Service] Type=oneshot User=root EnvironmentFile=/etc/backup.env ExecStart=/usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/sbin/backup.sh RemainAfterExit=true [Install] WantedBy=multi-user.target This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,49 @@ #!/bin/bash # Local backup script, adapted from https://webworxshop.com/centralised-backups-with-restic-and-rsync/ # Place in /usr/sbin/backup.sh # Enable with `systemctl enable backup.timer` # Check status with `systemctl status backup.service` set -e # Check variables if [ -z "$BACKUP_DEST" ]; then echo "BACKUP_DEST must be set" exit 1 fi if [ -z "$RESTIC_REPOSITORY" ]; then echo "RESTIC_REPOSITORY must be set" exit 1 fi if [ -z "$RESTIC_PASSWORD_FILE" ]; then echo "RESTIC_PASSWORD_FILE must be set" exit 1 fi if [ -Z "$BACKUP_DIRS" ]; then echo "BACKUP_DIRS must be set" exit 1 fi DIRS=$(echo $BACKUP_DIRS | tr ";" "\n") # rsync excludes EXCLUDES="--exclude=.cargo/registry --exclude=.toolchains --exclude=target --exclude=go/pkg --exclude=go/src --exclude=.cache --exclude=.mozilla" function do_rsync() { # Write start info to log file echo "Starting rsync backup job $1 to $BACKUP_DEST$1 at $(date '+%Y-%m-%d %H:%M:%S')..." # Ensure backup directory exists mkdir -p $BACKUP_DEST$1 # Execute rsync /usr/bin/rsync -aP --delete $EXCLUDES $1 $BACKUP_DEST # Write end-info to log file echo "Rsync job finished at $(date '+%Y-%m-%d %H:%M:%S')." @@ -36,12 +53,9 @@ function do_rsync() { echo "Starting rsync clone" for D in $DIRS; do do_rsync $D done # copy apt list dpkg --get-selections > $BACKUP_DEST/packages.list @@ -54,8 +68,9 @@ restic check # Execute backups for D in $DIRS; do restic backup $BACKUP_DEST/$D done # Clean up old snapshots -
ryankurte revised this gist
Mar 18, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ #!/bin/bash # Local backup script, adapted from https://webworxshop.com/centralised-backups-with-restic-and-rsync/ # Place in /usr/sbin/backup.sh # Enable with `sudo systemctl enable backup.timer` # View status with `sudo systemctl list-timers --all` and `sudo systemctl status backup.service` set -e -
ryankurte created this gist
Mar 18, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ # Systemd unit for backup.sh service # Place in /etc/systemd/system/backup.service [Unit] Description=Daily backup service [Service] Type=oneshot User=root ExecStart=/usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/sbin/backup.sh RemainAfterExit=true [Install] WantedBy=multi-user.target This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ #!/bin/bash # Local backup script, adapted from https://webworxshop.com/centralised-backups-with-restic-and-rsync/ # Place in /usr/sbin/backup.sh set -e # Backup file destination BACKUP_DEST=/media/large1/backups # rsync excludes EXCLUDES="--exclude=.cargo/registry --exclude=.toolchains --exclude=target --exclude=go/pkg --exclude=go/src --exclude=.cache --exclude=.mozilla" # Set restic globals export RESTIC_REPOSITORY=$BACKUP_DEST/restic export RESTIC_PASSWORD_FILE=/root/.restic.pass function do_rsync() { # Write start info to log file echo "Starting rsync backup job $1 to $BACKUP_DEST/raw$1 at $(date '+%Y-%m-%d %H:%M:%S')..." # Ensure backup directory exists mkdir -p $BACKUP_DEST/raw$1 # Execute rsync /usr/bin/rsync -aP --delete $EXCLUDES $1 $BACKUP_DEST/raw # Write end-info to log file echo "Rsync job finished at $(date '+%Y-%m-%d %H:%M:%S')." echo "Done" } echo "Starting rsync clone" # rsync home directories do_rsync /home # rsync configuration do_rsync /etc # copy apt list dpkg --get-selections > $BACKUP_DEST/packages.list echo "Starting restic backup" # Check database restic check # Execute backups restic backup $BACKUP_DEST/raw/home restic backup $BACKUP_DEST/raw/etc # Clean up old snapshots restic forget -d 7 -w 4 -m 6 -y 2 # Re-check the database restic check This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ # Systemd timer for backup.sh service # Place in /etc/systemd/system/backup.timer [Unit] Description=Daily backup service [Timer] OnCalendar=*-*-* 4:00:00 [Install] WantedBy=timers.target