Skip to content

Instantly share code, notes, and snippets.

@Maxopoly
Last active November 26, 2019 01:42
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 Maxopoly/42604f662d7b0748e11ba56da004a158 to your computer and use it in GitHub Desktop.
Save Maxopoly/42604f662d7b0748e11ba56da004a158 to your computer and use it in GitHub Desktop.
Backup script
#!/bin/bash
#Adjust to your personal needs and schedule on a cronjob running every minute by running "crontab -e"
#and adding "* * * * * bash /home/max/scr/backup.sh". Obviously adjust the path as needed
cryptFolder=/home/max/crypt/vault/
#Highly recommend using a private repo here to avoid meta data extraction by third parties
remote=git@github.com:Maxopoly/files.git
branch=master
#Adjust client name for each client so you can distinguish in the commit history who made a change
clientName=desktop
#mkdir is atomic, which we use here to ensure two instances of the script dont run at the same time
mutexDir=/tmp/backupcrypt.lock
if mkdir "$mutexDir"
then
cd $cryptFolder
git checkout master
git fetch $remote master:temp
git rebase temp
git branch -d temp
git add .
git commit -m "$clientName"
git push $remote master:master
rm -rf "$mutexDir"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment