Git automates backup and recovery data examples

Source: Internet
Author: User
Tags commit svn

Git is currently a popular distributed project versioning system, compared to SVN has a great advantage, yesterday was thinking that you should make good use of git, so I think you can use git version fallback, etc. to do a simple project automatic backup and recovery functions. This allows you to use GIT to do project versioning and to use Git as a backup. This makes it easy to migrate, back up, and so on.
Features and implementations are really simple, but here are a few prerequisites, first of all, the need to have their own Linux server, some simple shell programming, and finally familiar with some of GIT's related commands.
GitHub is a very popular remote library for git at the moment, my project because is individual, and does not have any commercial or the security nature, therefore uses the GitHub to do the remote storehouse, if has the request to this aspect, may give the GitHub to pay some protection fee, uses its private protection version storehouse, or, In your own server, build a remote library service, also very simple, online git a lot of information. Https://github.com/zhangcunchao, this is my first GitHub account, I will be a number of their own development projects, learning proceeds to put on the management, because this is very convenient.
The steps to implement are very simple,
First, install Git,centos on your own server using yum install git


This tutorial is not long, basically look down, git use basically no problem
Then, in GitHub or our own Remote version library, we create a version library that synchronizes the local project git library with the remote library,
Finally, shell script, do timed task, do git push synchronous remote
Because I do not have log analysis scripts and data backup scripts, will make changes to the project, so every day I will automatically sync once, that is, back up once the project to GitHub
So I put it in the script of my data backup.

  code is as follows copy code

#!/bin/sh
user= ' xxxx '
pwd= ' xxxx '
mysqldump-u$user-p$pwd--opt xxx> xxxxx.sql
mysqldump-u$user-p$pwd--opt xx x> xxxx.sql
mysqldump-u$user-p$pwd--opt xxx> xxxx.sql
#git push
cd/xxx/xxx/www.521php.com
git ad D. 1>/dev/null 2>&1
git commit-m "everyday push" 1>/dev/null 2>&1
git push 1>/dev/null 2>& Amp;1
 
cd/xxx/xxx/love.521php.com
git Add. 1>/dev/null 2>&1
git commit-m "everyday push "1>/dev/null 2>&1
git push 1>/dev/null 2>&1
Exit 0

If you need to restore a version, you only need to checkout a remote library version
git this distributed version management system and SVN still have a lot of differences, there are many advantages. This backup uses the SSH protocol, which is very fast. Git has a lot of advantages, I hope you can learn to use it.
PS: In order to be as safe as possible, you can set up. Gitignore to mask Some of the sync directories so that you can screen the sensitive profiles inside, and you can use a directory to store them exclusively.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.