Use Git to back up web files on Linux

Source: Internet
Author: User

Use Git to back up web files on Linux

BUP is not just Git, but a Git-based software. generally, I use rsync to back up my files, and I have been working very well so far. the only disadvantage is that the file cannot be restored to a specific time point. as a result, I began to look for alternatives and found a BUP, a git-based software that stores data in a repository and has the option of restoring data to a specific time point.

To use BUP, you must first Initialize an empty warehouse and then back up all files. when the BUP completes a backup, it will create a restore point, and you can restore it here later. it also creates indexes for all files, including file attributes and verification and. when you want to perform the next backup, The BUP will compare the properties and verification of the file and only save the changed data. this saves a lot of space.

Install BUP (tested on CentOS 6 & 7)

First, make sure that you have installed the RPMFORGE and EPEL repositories.

  1. [Techarena51 @ vps ~] $ Sudo yum groupinstall "Development Tools"
  2. [Techarena51 @ vps ~] $ Sudo yum install python-devel
  3. [Techarena51 @ vps ~] $ Sudo yum install fuse-python pyxattr pylibacl
  4. [Techarena51 @ vps ~] $ Sudo yum install perl-Time-HiRes
  5. [Techarena51 @ vps ~] $ Git clone git: // github.com/bup/bup
  6. [Techarena51 @ vps ~] $ Cd bup
  7. [Techarena51 @ vps ~] $ Make
  8. [Techarena51 @ vps ~] $ Make test
  9. [Techarena51 @ vps ~] $ Sudo make install

For debian/Ubuntu users, you can use "apt-get build-dep bup". For more information, see the https://github.com/bup/bup

On CentOS 7, an error may occur when you run "make test", but you can continue to run "make install ".

Initialize an empty repository in step 1, just like git.

  1. [Techarena51 @ vps ~] $ Bup init

By default, the bup stores the repository in "~ /. Bup ", but you can change the setting by setting the environment variable" export BUP_DIR =/mnt/user/bup.

Then, create indexes for all files. as mentioned earlier, this index stores a series of files, their attributes, and git target id (sha1 hash table ). (attributes include soft links, permissions, and unchangeable bytes)

  1. Bup index/path/to/file
  2. Bup save-n nameofbackup/path/to/file
  3.  
  4. # Example
  5. [Techarena51 @ vps ~] $ Bup index/var/www/html
  6. Indexing: 7973, done (4398 paths/s ).
  7. Bup: merging indexes (7980/7980), done.
  8.  
  9. [Techarena51 @ vps ~] $ Bup save-n techarena51/var/www/html
  10.  
  11. Reading index: 28, done.
  12. Saving: 100.00% (4/4 k, 28/28 files), done.
  13. Bloom: adding 1 file (7 objects ).
  14. Processing index from server: 1268/1268, done.
  15. Bloom: adding 1 file (7 objects ).

"BUP save" splits all content into blocks and stores them as objects. "-n" specifies the backup name.

You can view the backup list and backed up files.

  1. [Techarena51 @ vps ~] $ Bup ls
  2. Local-etc techarena51 test
  3. # Check for a list of backups available for my site
  4. [Techarena51 @ vps ~] $ Bup ls techarena51
  5. 2014-09-24-0644162014-09-24-071814 latest
  6. # Check for the files available in these backups
  7. [Techarena51 @ vps ~] $ Bup ls techarena51/2014-09-24-064416/var/www/html
  8. Apc. php techarena51.com wp-config-sample.php wp-load.php

Backing up files on the same server is never a good choice. BUP allows you to remotely back up web files, but you must ensure that your SSH key and BUP have been installed on the remote server.

  1. Bup index path/to/dir
  2. Bup save-r remote-vps.com-n backupname path/to/dir
Example: Back up the "/var/www/html" folder
  1. [Techarena51 @ vps ~] $ Bup index/var/www/html
  2. [Techarena51 @ vps ~] $ Bup save-r user@remotelinuxvps.com:-n techarena51/var/www/html
  3. Reading index: 28, done.
  4. Saving: 100.00% (4/4 k, 28/28 files), done.
  5. Bloom: adding 1 file (7 objects ).
  6. Processing index from server: 1268/1268, done.
  7. Bloom: adding 1 file (7 objects ).
Restore backup

Log on to the remote server and enter the following command

  1. [Techarena51 @ vps ~] $ Bup restore-C./backup techarena51/latest
  2.  
  3. # Restore an older version of the entire working dir elsewhere
  4. [Techarena51 @ vps ~] $ Bup restore-C/tmp/bup-out/testrepo/2013-09-29-195827
  5. # Restore one individual file from an old backup
  6. [Techarena51 @ vps ~] $ Bup restore-C/tmp/bup-out/testrepo/2013-09-29-201328/root/testbup/binfile1.bin

The only drawback is that you cannot restore the file to another server. You must manually copy the file through SCP or rsync.

View the backup through the integrated web server.

  1. Bup web
  2. # Specific port
  3. Bup web: 8181

You can use the shell script to run the bup and create a daily scheduled task.

  1. #! /Bin/bash
  2.  
  3. Bup index/var/www/html
  4. User@remote-vps.com:-n techarena51/var/www/html

BUP is not perfect, but it can indeed complete tasks well. Of course, I am very willing to see further development of this Project and hope to add remote recovery functions in the future.

You may like to read how to use inotify-tools for real-time file synchronization:

Real-time synchronization of the RHCE series ---- Rsync + Inotify-Tools

Inotify-tools + rsync real-time file synchronization installation and configuration

Linux git command parameters and Usage Details

Fedora downloads Git through Http Proxy

Install Git on Ubuntu Server

Create a Git repository on the server (Ubuntu)

Git simple tutorial in Linux (taking Android as an example)

Git authoritative guide PDF

Git details: click here
Git: click here

This article permanently updates the link address:

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.