How I created an Auto-backup using Git
During work we use to have a really stressful time.
Everyone was using each other's folders
(mainly happens in new projects... and an overenthusiastic project designer).
After 3-4 accidental deletions of my project folder,
I decided to simply backing up once a day is not enough.
So I created a bash file, copy the files and committing them via git
(an excellent way to manage your source code).
If anyone wants to use it, here it is:
I created a file and wrote:
1
2
3
4
5
6
7
8
#!/bin/sh
dir1=/var/www/html/me/projects/$1/
dir2=~/backups/$2/
rsync -vurgop --max-delete=1 --exclude '.git' $dir1 $dir2
cd $dir2
git add -v --ignore-errors *
filename="Backup_"`date +%Y%m%d%H%M`
git commit -aqnm $filename
1
*/10 * * * * ~/rsyncer.sh project project
This means run every 10 minutes the file ~/rsyncer.sh with the parameters project & project.
This might be inefficient, however it does a great job saving me rom any deletion
since my work is being saved every 10 minutes on another place.
I would love to hear about other solutions.