Linux VPS Automatically backup web and MySQL database scripts _linux

Source: Internet
Author: User
Tags vps strong password
Use a VPS to do everything you need to worry about, backup is also. Backup services like Linode are charged, and one months is 5 dollars. It's better to have plenty of money than to spend 5 dollars. Install the Dropbox for the service and set the Sync service to 4:00-6:00 on a daily basis. Run two scripts before, automatically back up Web folders and MySQL databases.
All two scripts are backed up to the/root/dropbox/backup directory, and the backup is automatically deleted 10 days ago. A Web backup is a weekly row that deletes a backup 30 days ago.

one, back up Web Folders

1, Backup/home/users/public_html directory
2. Modify crontab to run on the first day of the week 3:22
Copy Code code as follows:

3 * * 0 root run-parts/etc/cron.weekly

3. Copy script to/etc/cron.weekly directory
4, modify the permissions
Copy Code code as follows:

chmod 0755/etc/cron.weekly/webbackup.sh

5, the script is as follows
Copy Code code as follows:

#!/bin/sh
Filename= ' Date +%y%m%d '
Backup_dir= "/root/dropbox/backup/web"
#delete All files ten days ago
Find $backup _dir-mtime +30-name "*"-exec rm-rf {} \;
#each user you want backup
users= "Baidu Sina"
For user in ${users}; Todo
Tar zcvf $backup _dir/$user $filename.tar.gz/home/$user/public_html
Done

6, note that the sentence filename is not single quotes, above the TAB key
7, to back up the user's public_html directory, the user will be filled into the users

second, MySQL database daily backup

1, for security, new user backup, with strong password (automatically generated), global permissions for Select,lock tables
2, daily 3:00 to start the implementation, modify Crontab
3. Copy script to/etc/cron.daily
4, modify the permissions
5, script content
Copy Code code as follows:

#!/bin/sh
Dbuser= "Backup"
Dbpassword= "Youpassword"
datas= "DB1 DB2 db3"
Filename= ' Date +%y%m%d '
Bin_dir= "/usr/local/mysql/bin"
Backup_dir= "/root/dropbox/backup/mysql"
#delete All files ten days ago
Find $backup _dir-mtime +10-name "*"-exec rm-rf {} \;
#Do each database backup
For data in ${datas}; Todo
$bin _dir/mysqldump--opt-u$dbuser-p$dbpassword $data | gzip > $backup _dir/$data $filename.sql.gz
Done

6, the same as the 6th article
7, to back up the database to fill in the Datas

third, the feeling

Because of all the reasons in the United States, backup to Dropbox fast, a 10M file backup to Dropbox, from the open Dropbox service, immediately refresh Dropbox site can be seen.
If the flow is very tense, you can also set the Dropbox for the weekly run, or every 5 days running and so on. It should be required to set up a backup cycle, or use it together.
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.