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.
- [Techarena51 @ vps ~] $ Sudo yum groupinstall "Development Tools"
- [Techarena51 @ vps ~] $ Sudo yum install python-devel
- [Techarena51 @ vps ~] $ Sudo yum install fuse-python pyxattr pylibacl
- [Techarena51 @ vps ~] $ Sudo yum install perl-Time-HiRes
- [Techarena51 @ vps ~] $ Git clone git: // github.com/bup/bup
- [Techarena51 @ vps ~] $ Cd bup
- [Techarena51 @ vps ~] $ Make
- [Techarena51 @ vps ~] $ Make test
- [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.
- [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)
- Bup index/path/to/file
- Bup save-n nameofbackup/path/to/file
-
- # Example
- [Techarena51 @ vps ~] $ Bup index/var/www/html
- Indexing: 7973, done (4398 paths/s ).
- Bup: merging indexes (7980/7980), done.
-
- [Techarena51 @ vps ~] $ Bup save-n techarena51/var/www/html
-
- Reading index: 28, done.
- Saving: 100.00% (4/4 k, 28/28 files), done.
- Bloom: adding 1 file (7 objects ).
- Processing index from server: 1268/1268, done.
- 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.
- [Techarena51 @ vps ~] $ Bup ls
- Local-etc techarena51 test
- # Check for a list of backups available for my site
- [Techarena51 @ vps ~] $ Bup ls techarena51
- 2014-09-24-0644162014-09-24-071814 latest
- # Check for the files available in these backups
- [Techarena51 @ vps ~] $ Bup ls techarena51/2014-09-24-064416/var/www/html
- 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.
- Bup index path/to/dir
- Bup save-r remote-vps.com-n backupname path/to/dir
Example: Back up the "/var/www/html" folder
- [Techarena51 @ vps ~] $ Bup index/var/www/html
- [Techarena51 @ vps ~] $ Bup save-r user@remotelinuxvps.com:-n techarena51/var/www/html
- Reading index: 28, done.
- Saving: 100.00% (4/4 k, 28/28 files), done.
- Bloom: adding 1 file (7 objects ).
- Processing index from server: 1268/1268, done.
- Bloom: adding 1 file (7 objects ).
Restore backup
Log on to the remote server and enter the following command
- [Techarena51 @ vps ~] $ Bup restore-C./backup techarena51/latest
-
- # Restore an older version of the entire working dir elsewhere
- [Techarena51 @ vps ~] $ Bup restore-C/tmp/bup-out/testrepo/2013-09-29-195827
- # Restore one individual file from an old backup
- [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.
- Bup web
- # Specific port
- Bup web: 8181
You can use the shell script to run the bup and create a daily scheduled task.
- #! /Bin/bash
-
- Bup index/var/www/html
- 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: