db-backup-cron.sh 987 B

1234567891011121314151617181920212223242526272829
  1. #!/bin/sh
  2. # path to your local repository
  3. LOCAL_REPO='/storage/db_backups'
  4. # specify a timeout for ssh-agent to live in seconds; otherwise its forever
  5. TIMEOUT='150'
  6. # specify which private key to use (the pubkey should already be in ~/.ssh/authorized_keys on the remote server)
  7. # as well as the fingerprint stored locally in known_hosts (do a manual pull the first time you set this up)
  8. # note that if you have a password on your key, it'll bungle this script up unless you add additional processing for the pw
  9. USEKEY='~/.ssh/your_private_key'
  10. # see if a vpn connection is active, i use openvpn
  11. if [ "$(pgrep -a openvpn)" = "" ];
  12. then
  13. cd "$LOCAL_REPO" && \
  14. ssh-agent bash -c "ssh-add -t "$TIMEOUT" "$USEKEY"; git pull 2>&1" && \
  15. cd && \
  16. notify-send -i git-gui "Remote Database Backup" -u critical "Weekly backup complete, at $LOCAL_REPO"
  17. else
  18. # vpn detected, abort
  19. notify-send -i gnome-warning "Remote Database Backup" -u critical "DB Backup failed; VPN detected"
  20. fi