Skip to content

Instantly share code, notes, and snippets.

@brodul
Created September 4, 2015 12:49
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 brodul/bb4abcd6978fe42438a7 to your computer and use it in GitHub Desktop.
Save brodul/bb4abcd6978fe42438a7 to your computer and use it in GitHub Desktop.
#!/bin/bash
# this is runned as backup_user
# the user is in the backup group
# Add key
if [ -z "$SSH_AUTH_SOCK" ] ; then
eval `ssh-agent -s`
ssh-add
fi
#
HOST='10.66.0.XXX'
REPOSITORY=10.66.0.XXX:/srv/backup/dbrep.attic
ssh $HOST bash -c "'
# do db dumping
# Backup all of /home and /var/www except a few
# excluded directories
borg create --stats \
$REPOSITORY::store_dbs-`date +%Y-%m-%d`--$RANDOM \
/home/backup_user/all_databases.sql \
/home/backup_user/*.txt
# Use the prune subcommand to maintain 7 daily, 4 weekly
# and 6 monthly archives.
borg prune -v $REPOSITORY --keep-daily=7 --keep-weekly=4 --keep-monthly=6
'"
# could be killed nicer agent returns PID but https://www.youtube.com/watch?v=137zL_goITs
pkill ssh-agent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment