Push backups automatically to Git Repository

Push backups automatically to Git Repository or Cloud is very useful for your protecting database data.To automatically push backup to git repository, we have to certain things first.

1. Create Git repository and setup.
if you are unfamiliar with git using follow this link know how to install and setup git: Git Setup
2. Enable SSH authentication with your system.
(if you choose HTTPS over SSH, you have to enter password always when you push.In our case this is not possible.So you have to setup SSH in your server/local system.It’s not a complex process)
follow this link to know how to setup install and setup SSH in your system :SSH setup
3. Write a bash script to execute and set it as cron.

You can use the following link to set up Git repository :
SSH authentication is also well explained in ,y previous post.Just follow this link :
Add your SSH public key to your Git repository and you are done.

Next we have to create a bash script and set it as a cron job :

 
  5 3 * * *   root    /home/Development/Bash_scipts/./dbbackupload.sh

Bash Script for executing the cron :

#!/bin/bash
## Upload mysql DB backup to cloud ##

 cd /home/Development/db_backup/filename.tar.gz;
 git add -A;
 git commit -m "Automatic DB backup push";
 git push origin master;

The above bash script is a simple one.You can modify this one according to your needs and set your own cron jobs. Also, this script contains all the necessarily git commands to push the backups to your repository.

Note: You can add the SSH public key to your git repository, most of the on line repositories provides an option for that.But, i am using Bitbucket. Consider the space in your repository and use it wisely, if you are using an free account.