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 in your root directory, like

cd ~ vi

now press i button to insert following commands

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

Step 2: Give proper execution rights

chmod +x

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/

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


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

Tural Aliyev

I'm traveloholic, musicphile, technoholic, cinephile, workaholic software developer


Subscribe to Tural's Notebook

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!