/ backup

Project's daily backup using GIT

I’m always deploying my projects using GIT. One of the key points in project’s security is backing it up in daily basis. So I came up with GIT based daily backup solution which cover’s SQL backup also.

Assuming that, you already setup git repository on your production server. And you’re using MySQL DB (because I’m using mysqldump command. Perhaps you can use another one)

Step 1: Create backup shell script

Create file named backup.sh in your root directory, like

cd ~ vi backup.sh

now press i button to insert following commands

cd /project's/directory mysqldump -u root --password=your_password database_name > backup.sql git add -A . git commit -m "daily backup" git push

Step 2: Give proper execution rights

chmod +x backup.sh

Step 3: Create cronjob to execute this file daily

For example if you want to execute this script daily in 00:00, write following line:

crontab -e 0 0 * * * /root/backup.sh

BTW, I’m assuming that our file located in root directory

/root/backup.sh

Well done!

Note 1: If you want to check if cron executed properly, use following command (for Debian and it’s distros)

grep CRON /var/log/syslog

Note 2: If you want to execute cron based on your local timezone read my previous article