Skip to content

Instantly share code, notes, and snippets.

@myersjustinc
Created March 31, 2019 06:24
Show Gist options
  • Save myersjustinc/3829a08c141d545f213ab226b0060def to your computer and use it in GitHub Desktop.
Save myersjustinc/3829a08c141d545f213ab226b0060def to your computer and use it in GitHub Desktop.
Duplicity backup script
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
BASE_DIR='[REDACTED]'
mkdir -p "${BASE_DIR}"
STATUS_FILE="${BASE_DIR}/duplicity.running"
function finish {
rm "${STATUS_FILE}"
}
trap finish EXIT
LOG_DIR="${BASE_DIR}/logs"
mkdir -p "${LOG_DIR}"
LOCAL_SOURCE_DIR='[REDACTED]'
SFTP_CONNECTION='[REDACTED]'
SFTP_DIRECTORY='[REDACTED]'
export PASSPHRASE='[REDACTED]'
echo "obtaining collection status" > "${STATUS_FILE}"
set +e # In case we need to wake up the remote SFTP server
duplicity \
collection-status \
--log-file "${LOG_DIR}/$( date --utc '+%Y%m%d-%H%M%S' )-status.log" \
--verbosity 'notice' \
"paramiko+sftp://${SFTP_CONNECTION}/${SFTP_DIRECTORY}"
set -e
echo "running backup" > "${STATUS_FILE}"
duplicity \
--full-if-older-than '3M' \
--include-filelist "${BASE_DIR}/config/include.txt" \
--log-file "${LOG_DIR}/$( date --utc '+%Y%m%d-%H%M%S' )-backup.log" \
--verbosity 'notice' \
"${LOCAL_SOURCE_DIR}" \
"paramiko+sftp://${SFTP_CONNECTION}/${SFTP_DIRECTORY}"
echo "removing outdated backups" > "${STATUS_FILE}"
duplicity \
remove-all-but-n-full '2' \
--force \
--log-file "${LOG_DIR}/$( date --utc '+%Y%m%d-%H%M%S' )-remove.log" \
--verbosity 'notice' \
"paramiko+sftp://${SFTP_CONNECTION}/${SFTP_DIRECTORY}"
echo "cleaning up unnecessary backup files" > "${STATUS_FILE}"
duplicity \
cleanup \
--force \
--log-file "${LOG_DIR}/$( date --utc '+%Y%m%d-%H%M%S' )-cleanup.log" \
--verbosity 'notice' \
"paramiko+sftp://${SFTP_CONNECTION}/${SFTP_DIRECTORY}"
echo "done" > "${STATUS_FILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment