Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to automatically back up files and send them to Gmail

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to automatically back up files and send to Gmail, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

First, install the required programs

Yum install-y mutt vixie-cron

Second, set mutt sending parameters

$vim ~ / .muttrc

Write the following

Set envelope_from=yes

Set from=bak@deepvps.com

Set realname= "DiaBak"

Set use_from=yes

Then set the Gmail to receive mail and add bak@deepvps.com to the whitelist.

Third, set up the script

Pay attention to these directories

/ etc/cron.hourly

/ etc/cron.daily

/ etc/cron.weekly

/ etc/cron.monthly

Files in these directories can be executed automatically every hour, every day, every week, and once a month.

If you are placing the script in the directory above, it is best to set the permission to 0700.

You can use the crontab-e command to set more complex execution conditions. Please refer to Baidu for details.

Take daily execution as an example

$vim / etc/cron.daily/diabsk.sh

Write the following

#! / bin/bash

# SETTING

TOEMAIL= "bak@deepvps.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 20m-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 30s

Done

Rm-rf $ATTTMP

The content that needs to be changed has been added red.

TOEMAIL is the email address from which the mail is received.

TOEMAIL is an annotated message that is sent as the body of the message.

DIR is a temporary directory name, it is recommended to use only English and numbers.

# Put files what you want to backup to $TMP, the following commands on this line can be added as needed, such as backup database can export SQL files to $TMP directory, backup files can copy files to $TMP directory.

Fourth, the command to export the database.

1. Back up a single database

Mysqldump-user=user-password=password-lock-all-tables dbname > backup.sql

two。 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 to prevent changes during backup, thus causing multiple related tables to be out of sync. For example, table A needs to refer to table B, and table B changes after table An is backed up, so the database is messed up.

It only takes a few seconds to back up hundreds of megabytes of databases, so this option has little impact on the operation of the site.

Fifth, reassemble the backed-up files

Under Linux

$cat DiaBak* > bak.tar.gz

Under 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 volume, and the cat command will reassemble the files in the order of these numbers, so the numbers cannot be messed up.

The same goes for the copy command, paying attention to the order of numbers.

Six, other

Tested a file of more than 600m, divided into 31 packets with the size of 20m, sent by script, took more than ten minutes, during which the network speed was maintained between 5Mbps and 10Mbps, and the machine still had enough bandwidth, which should be the upper limit of GMAIL.

Some emails take more than an hour to show up on Gmail. All 31 bags have been received.

After reading the above, do you know how to automatically back up files and send them to Gmail? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report