Skip to content

Instantly share code, notes, and snippets.

@brikeats
Last active August 26, 2016 20:40
Show Gist options
  • Save brikeats/721656e26937a3824e4cf59f656390aa to your computer and use it in GitHub Desktop.
Save brikeats/721656e26937a3824e4cf59f656390aa to your computer and use it in GitHub Desktop.
Backup script for OSX. Takes incremental snapshots and puts them in folders with the date/time.
#!/bin/bash
LOG_FOLDER=~/MineAnnotationsBackup/logs
BACKUP_FOLDER=~/MineAnnotationsBackup
# script from here: http://www.howtogeek.com/175008/the-non-beginners-guide-to-syncing-data-with-rsync/
#copy old time.txt to time2.txt
yes | cp $LOG_FOLDER/time.txt $LOG_FOLDER/time2.txt
#overwrite old time.txt file with new time
echo `date +%F-%I%M` > $LOG_FOLDER/time.txt
echo `date +%F-%I%M`
#make the log file
echo '' > $LOG_FOLDER/rsync-`date +%F-%I%M`.log
#rsync command
rsync -avzhPR --no-relative --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --delete --stats --log-file=${LOG_FOLDER}/rsync-`date +%F-%I%M`.log --link-dest=$BACKUP_FOLDER/`cat $LOG_FOLDER/time2.txt` '/Users/bkeating/Box Sync/Mine Annotations' ${BACKUP_FOLDER}/`date +%F-%I%M`/
# #don’t forget to scp the log file and put it with the backup
# scp -P 12345 ~/backup/rsync-`cat ~/backup/time.txt`.log geek2@10.1.1.1:/home/geek2/files/`cat ~/backup/time.txt`/rsync-`cat ~/backup/time.txt`.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment