Skip to content

Instantly share code, notes, and snippets.

@ftclausen
Last active June 11, 2019 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ftclausen/c9e0d5b34e7c4c5030fdde1c450731fc to your computer and use it in GitHub Desktop.
Save ftclausen/c9e0d5b34e7c4c5030fdde1c450731fc to your computer and use it in GitHub Desktop.
restic_wrapper.sh
#!/usr/bin/env bash
# Friedrich "Fred" Clausen - ftclausen@gmail.com
source_directories=("/var/tmp/inc_test" "/var/tmp/inc test 2")
remote="sftp:md:tmp/inc_test"
passwd="/tmp/pw"
report_location="/tmp"
log="$(mktemp -t backup_report_)"
sftp_log="$(mktemp)"
trap "{ echo \"Cleaning up...\"; rm -f \"$log\" \"$sftp_log\"; }" SIGINT SIGTERM EXIT INT
for dir in ${!source_directories[@]}; do
restic -r "$remote" backup --password-file "$passwd" "${source_directories[dir]}" 2>&1 | tee -a "$log"
done
restic -r "$remote" --password-file "$passwd" prune 2>&1 | tee -a "$log"
cat <<EOF &> "$sftp_log"
lcd ${log%/*}
cd $report_location/
put ${log##*/}
EOF
remote_host=$(echo $remote | awk -F ':' '{print $2}')
sftp -b "$sftp_log" $remote_host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment