The method of Dropbox network disk of Linux VPS host website database and file automatic timing backup

Source: Internet
Author: User
Tags chmod set time vps dropbox backup vps server git clone
Whether we choose to pay 10 dollars a month, or a year to pay 10 US dollars VPS, servers, whether we choose to set up a 3-month host, or choose to set up a 30-year host, as long as we choose to use and used to store useful data, such as Web sites. We all need to be prepared to keep and back up data, to understand the importance of data. We can choose to manually replicate backups locally, or we can choose to take advantage of snapshot backups or paid backup services provided by some hosts.






In this article, Chiang will continue to toss about a Linux VPS host environment in the Web site files and database backup method, back to the Dropbox network disk. Many of our friends should also have some understanding of this overseas network, is a relatively long and better service providers, but for a variety of reasons we can not directly open in the country, which determines if we need to back up the data in the domestic mainframe is not.






Therefore, in this document, if we are overseas host, server backup, you can choose Dropbox, free users to provide 2GB accounts, the general small site is no problem. The Dropbox network disk can also be used to synchronize the local computer's documentation, but in view of the security perspective, it is best not to synchronize the important account data, because we are still afraid of the case. (Old Chiang nonsense a heap, we start!))






First, obtain Dropbox authorized key account






We need to obtain an authorized account before we are ready to use the Dropbox network to synchronize the backup site data.






The code is as follows Copy Code

Get Authorization: Https://www.dropbox.com/developers/apps/create












We need to create an application, as shown in the previous illustration.












Get the app key and app secret that we need to configure the authorization later.






Second, deploy Dropbox backup authorization script






The code is as follows

git clone https://github.com/andreafabrizi/Dropbox-Uploader/
CD Dropbox-uploader
chmod + x dropbox_uploader.sh
mkdir / home / backup /
MV dropbox_uploader.sh/home/backup/






If we cannot execute git, we also need to install Yum install git-y in advance so that authorization is required after the deployment is complete.






The code is as follows

./dropbox_uploader.sh












According to the illustration above, we enter the authorization confirmation address given in the browser.












So we confirm the authorization, complete. This allows us to complete the current VPS server and Dropbox authorization.






Third, deploy a Web site backup script






The code is as follows

#! / bin / bash
# Settings
Dropbox_dir = "/ backups" #Folder name in Dropbox
Backup_src = "/home/wwwroot/laobuluo.com/home/wwwroot/laojiang.me" #Folder path to be backed up, you can specify multiple
backup_dst = "/ tmp" #Folder path used to store backup
Mysql_server = "127.0.0.1" #Connect to local MySQL
mysql_user = "Database User" #Local MySQL user
mysql_pass = "Database Password" #Local MySQL password

# Stop Editing here
now = $ (date + "% y.% m.% d")
destfile = "$ BACKUP _dst / $ NOW. tgz"
last = $ (date-d "2 months ago" + "% y.% m.% d") #The time here can be modified as needed, such as "3 months ago"

# Backup Files
Ps-e | Grep-c MySQL
If [$?-Eq 0]; Then
echo "Dumping databases ..."
/ usr / bin / mysqldump-u $ MYSQL _user-h $ MYSQL _server-p $ mysql_pass--all-databases> "$ BACKUP _dst / $ NOW-databases.sql" #The command path here can be modified as needed
Else
echo "ERROR. Now exiting ..."
Exit 1
Fi

If [$?-Eq 0]; Then
echo "Packing files ..."
Tar-czf "$ DESTFILE" $ BACKUP _src "$ BACKUP _dst / $ NOW-databases.sql"
Else
echo "ERROR. Now exiting ..."
Exit 1
Fi

If [$?-Eq 0]; Then
/home/backup/dropbox_uploader.sh upload "$ DESTFILE" "$ DROPBOX _dir / $ NOW. tgz" #The script path here can be modified as needed
Else
echo "ERROR. Now exiting ..."
Exit 1
Fi

# Delete old files
If [$?-Eq 0]; Then
/home/backup/dropbox_uploader.sh Delete "$ DROPBOX _dir / $ LAST. tgz" #The script path here can be modified as needed
Else
echo "ERROR. Now exiting ..."
Exit 1
Fi

If [$?-Eq 0]; Then
echo "Cleaning the backups ..."
Rm-f "$ BACKUP _dst / $ NOW-databases.sql"
Rm-f "$ BACKUP _dst / $ LAST. Tgz"
Else
echo "ERROR. Now exiting ..."
Exit 1
Fi






We can change the script above and then name it dropbox-backup.sh, where I'll put a download document:






The code is as follows

http://soft.itbulu.com/tools/dropbox-backup.sh






We modify the corresponding parameters according to the actual website project needs. It is then placed in a directory known to the VPS itself, as it is necessary to perform and configure scheduled backups.






The code is as follows

chmod + x dropbox-backup.sh

./dropbox-backup.sh






This will automatically back up the Web site files and databases to our corresponding Dropbox network disk. To mention here, we can first add one in the directory to the Network Disk folder set up in the above parameter and.






Four, set up a scheduled backup script






The code is as follows

Crontab–e






Edit the timed script and add:






The code is as followsup.sh






Here we set a daily 3:30 to perform a scheduled backup, we can also set time a little longer, generally according to the site's data update degree to decide.






The use of Dropbox Backup Web site Summary






1, because Dropbox only overseas IP access, so can not back up the domestic host Web site data. And the net disk free user limit 2GB, so the backup file can not exceed the size of the network disk, but cannot be backed up.






2, the backup process setup is relatively simple, get the corresponding authorization code after the pairing is completed and then add custom modified the backup site script execution. It is necessary to set the timed time according to the amount of data added.


3 * * * / root / dropbox-back

Related Article

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.