Centos website server uses the DropBox regular backup solution

Source: Internet
Author: User
Not long ago, due to the DS issue, many of the previous data were lost. although not very important, I also learned the importance of data backup. As a webmaster, no matter whether it is a virtual host, vps or a single server, it is very important to have good data backup habits. I am also a little white man. After I lost data, I quickly went to the Internet to find and learn. here I will extract a good VPS data backup solution: first, I will introduce the main character & ndash; dropbox, DropB

Not long ago, due to the DS issue, many of the previous data were lost. although not very important, I also learned the importance of data backup. As a webmaster, no matter whether it is a virtual host, vps or a single server, it is very important to have good data backup habits.

I am also a little white man. After I lost data, I quickly went to the Internet to find and learn. here I will extract a good VPS data backup solution:

First, we will introduce Dropbox, the main character here. DropBox is a very useful free network file synchronization tool or service, similar to Kingsoft fast disk in China, this allows you to easily back up files on your computer or synchronize them to another computer. If you do not go into details, go to the topic:

1. install and configure Dropbox:

Dropbox provides the client for different operating systems. in Windows, it is relatively simple to install and set directly, and most of our VPS are linux operating systems. Therefore, we must first install dropbox on our VPS, select the following command to download dropbox based on the number of vps system digits:
32-bit:

Wget-O dropbox.tar.gz http://www.dropbox.com/download? Plat = lnx. x86

64-bit:

Wget-O dropbox.tar.gz http://www.dropbox.com/download? Plat = lnx. x86_64

Decompress the package:

Tar xzvf dropbox.tar.gz

After decompression, run the following command to run dropbox:

~ /. Dropbox-dist/dropboxd &

Generally, the following message is displayed instead of synchronizing the vps that is not associated with your dropbox account because it is the first time we run it:

This client is not linked to any account...

Please visit https://www.dropbox.com/cli_link? Host_id = XXXXXXXXXX & cl = en_US to link this machine.

Here dropbox has generated a host_id for your vps, copy the above prompt in https://www.dropbox.com/cli_link? Host_id = XXXXXXXXXX & cl = en_US this URL is opened in the browser, and then enter your account password, dropbox will automatically bind your account to your VPS.

II. create a backup

First, go to the dropbox Directory:

Cd ~ /Dropbox

Before starting the backup, we first need to use ln to soft link all the directories you want to back up, for example:

Ln-s/home/wwwroot/abc

Ln-s/home/wwwroot/bcd

You can add a directory based on your actual situation.

OK. run the following command to synchronize the dropbox:

~ /. Dropbox-dist/dropboxd &

3. create a scheduled backup script

By default, dropbox synchronizes data in real time. This is definitely very resource-consuming, and our vps can always save resources as much as possible, therefore, we need to set up the dropbox to synchronize only one time at intervals and then close the program to save resources.
First, disable synchronization:

Killall dropbox

Create and compile a scheduled synchronization script:

Vi backup. sh

Write the following code into the script:

#! /Bin/sh
Start (){
Echo starting dropbox
/Root/. dropbox-dist/dropboxd &
}
Stop (){
Echo stoping dropbox
Pkill dropbox
}
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Restart)
Stop
Start
;;
Esac

After saving, we need to add the execution permission to backup. sh:

Chmod + x backup. sh

Then, create a root file in the var \ spool \ cron directory or directly run the crontab-e command to add a scheduled run:
0 2 *** sh/root/backup. sh restart0 3 *** sh/root/backup. sh stop

Synchronization starts at and ends at. the running time can be adjusted based on the actual situation. The interval can also be changed based on the data volume to be synchronized directly.

4. Add database backup

First, create and edit the backup command:

Vi backupdb. sh

Write the following script. the specific script to be changed has been commented out clearly:

#! /Bin/bash
DBName = change to database name
DBUser = change to database user name
DBPasswd = change to database password
BackupPath =/root/Dropbox/
LogFile =/root/db. log
DBPath =/usr/local/mysql/var/# backup Database Directory
# BackupMethod = mysqldump
# BackupMethod = mysqlhotcopy
# BackupMethod = tar

NewFile = "$ BackupPath" db $ (date + % y % m % d). tgz
DumpFile = "$ BackupPath" db $ (date + % y % m % d)
OldFile = "$ BackupPath" db $ (date + % y % m % d-date = '5 days ago '). tgz # automatically deletes the backup five days ago.
Echo "---------------" >>$ LogFile
Echo $ (date + "% y-% m-% d % H: % M: % S") >>$ LogFile
Echo "---------"> $ LogFile
# Delete Old File
If [-f $ OldFile]
Then
Rm-f $ OldFile >>$ LogFile 2> & 1
Echo "[$ OldFile] Delete Old File Success !" >>$ LogFile
Else
Echo "[$ OldFile] No Old Backup File !" >>$ LogFile
Fi
If [-f $ NewFile]
Then
Echo "[$ NewFile] The Backup File is exists, Can't Backup !" >>$ LogFile
Else
Case $ BackupMethod in
Mysqldump)
If [-z $ DBPasswd]
Then
Mysqldump-u $ DBUser-opt $ DBName> $ DumpFile
Else
Mysqldump-u $ DBUser-p $ DBPasswd-opt $ DBName> $ DumpFile
Fi
Tar czvf $ NewFile $ DumpFile >>$ LogFile 2> & 1
Echo "[$ NewFile] Backup Success !" >>$ LogFile
Rm-rf $ DumpFile
;;
Mysqlhotcopy)
Rm-rf $ DumpFile
Mkdir $ DumpFile
If [-z $ DBPasswd]
Then
Mysqlhotcopy-u $ DBUser $ DBName $ DumpFile >>$ LogFile 2> & 1
Else
Mysqlhotcopy-u $ DBUser-p $ DBPasswd $ DBName $ DumpFile >>$ LogFile 2> & 1
Fi
Tar czvf $ NewFile $ DumpFile >>$ LogFile 2> & 1
Echo "[$ NewFile] Backup Success !" >>$ LogFile
Rm-rf $ DumpFile
;;
*)
Service mysql stop>/dev/null 2> & 1
Tar czvf $ NewFile $ DBPath $ DBName >>$ LogFile 2> & 1
Service mysql start>/dev/null 2> & 1
Echo "[$ NewFile] Backup Success !" >>$ LogFile
;;
Esac
Fi
Echo "---------------" >>$ LogFile

After saving, add the execution permission to backupdb. sh:

Chmod + x backupdb. sh

Then, run the crontab-e command in the root file under the var \ spool \ cron directory to add the regular run:
0 1 *** sh/root/backupdb. sh

Generally, I like to create a database backup before the dropbox operation, and the specific time can be adjusted by myself.

Finally, the method for deleting and uninstalling dropbox is attached:

Killall dropbox

Rm-rf. dropbox. dropbox-dist Dropbox dropbox.tar.gz dbmakefakelib. py dbreadconfig. py

The above code is provided by helps of houstloc. I only edit it and add some other gossips for notes ~

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.