Automatically backs up files on LinuxVPS and sends them to Gmail

Source: Internet
Author: User
& Nbsp; 1. install the required program yuminstall-ymuttvixie-cron. 2. set the mutt sending parameter $ vim ~ /. Muttrc write the following content setenvelope_fromyessetfrombak@diavps.comsetrealname "DiaBak" setuse_fromyes and then set the Gmail to receive the mail

1. install the required program

Yum install-y mutt vixie-cron
2. set the mutt sending parameters
$ Vim ~ /. Muttrc
Write the following content
Set envelope_from = yes
Set from = bak@diavps.com
Set realname = "DiaBak"
Set use_from = yes
Then set Gmail to receive the mail and add the bak@diavps.com to the White List.
3. set scripts
Note these directories
/Etc/cron. hourly
/Etc/cron. daily
/Etc/cron. weekly
/Etc/cron. monthly
Files in these directories can be automatically executed every hour, every day, every week, and every month.
If you want to place the script program in the preceding directory, you 'd better set the permission to 0700.
You can use the crontab-e command to set more complex execution conditions. For more information, see Baidu.
Take Daily execution as an example
$ Vim/etc/cron. daily/diabsk. sh
Write the following content
#! /Bin/bash
# SETTING
TOEMAIL = "bak@diavps.com ";
COMMENT = 'blog database backup'
DIR = 'wordpress'
# END SETTING
TMP = '/tmp/diabak/' $ {DIR}
ATTTMP = '/tmp/diabakatt/' $ {DIR}
Rm-rf $ TMP
Mkdir-p $ TMP
Cd $ TMP
# Put files what you want to backup to $ TMP
# Don't change anything below
YYYYMMDD = 'date + % Y % m % d'
SUBJECT = 'diabak _ of _ '$ {DIR}' _ $ {YYYYMMDD };
Rm-rf $ ATTTMP
Mkdir-p $ ATTTMP
Cd $ ATTTMP
Tar zcPf backup.tar.gz $ TMP
Rm-rf $ TMP
Split-B 20 m-a 3-d backup.tar.gz $ {SUBJECT}. part
Rm-f backup.tar.gz
For file in *
Do
Echo $ COMMENT | mutt-a $ file-s $ SUBJECT $ TOEMAIL
Sleep 30 s
Done
Rm-rf $ ATTTMP
The content to be changed has been highlighted
TOEMAIL is the email address for receiving emails.
TOEMAIL is a comment email sent in the body of the email.
DIR is the temporary directory name. we recommend that you only use English letters and numbers.
# Put files what you want to backup to $ TMP. the following commands in this line can be supplemented as needed. for example, you can back up the database and export the SQL file to the $ TMP directory, backup files can be copied to the $ TMP directory.
4. export database commands.
1. back up a single database
Mysqldump? User = user? Password = password? Lock-all-tables dbname> backup. SQL
2. back up multiple databases
Mysqldump? User = user? Password = password? Lock-all-tables? Databases dbname1 dbname2> backup. SQL
3. back up all databases
Mysqldump? User = user? Password = password? Lock-all-tables? All-databases> backup. SQL
? The lock-all-tables option can lock the database during backup to prevent changes, which may lead to the synchronization of multiple related tables. for example, if Table A needs to reference table B, after table A is backed up, table B is backed up only after it has changed, so that the database becomes messy.
It takes only a few seconds to back up a database of hundreds of MB, so this option has little impact on website operation.
5. recombine backup files
Linux
$ Cat DiaBak *> bak.tar.gz
Windows
Copy DiaBak_of_testfile_20100421.part001/B + DiaBak_of_testfile_20100421.part002/B bak.tar.gz
Note that there will be three digits after the split, and the cat command will re-combine the files in the order of these digits, so the numbers cannot be messy.
The copy command is the same. pay attention to the numerical order.
VI. others
I tested a file with a size of more than 600 MB and divided it into 31 packages at a size of 20 MB. the file was sent through a script and took 10 minutes. during this period, the network speed remained between 5 Mbps and 10 Mbps, the local machine still has enough bandwidth. This should be the GMAIL ceiling.
It may take more than an hour for some emails to be displayed in Gmail. All 31 packages are received.
If anyone finds a mailbox that is more suitable for backup than Gmail, I hope to share it with you.

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.