Linux Server build station data backup automatically upload FTP server

Source: Internet
Author: User

现在很多朋友通过购买云服务器建站,有时候由于服务器系统的问题,没有及时做好网站数据的备份而导致数据的丢失。如果你手中还有其他云服务器或者FTP服务器可以实现自动备份上传的功能。本文仅仅是做一个备份数据想法。
(1) Site data backup to the site data/var/www/vhost/www.51cto.com and/var/www/vhost/www.baidu.com separately back to:/data/code-backup/www.51cto.com and/ Under the data/code-backup/www.baidu.com. [[Email protected]_web5 code-backup]# cat web_code_backup.sh#!/bin/bash# Backup website Data/bin/tar-zvcf/data/code-backup /www.baidu.com/www.baidu.com_ ' Date +%y%m%d_%h%m%s '. tar.gz/var/www/vhosts/www.baidu.com/bin/tar-zvcf/data/ Code-backup/www.51cto.com/www.51cto.com_ ' Date +%y%m%d_%h%m%s '. tar.gz/var/www/vhosts/www.51cto.com# Delete backup files from a week ago Find/data/code-backup/www.baidu.com-type f-mtime +7-exec rm-f {} \;find/data/code-backup/www.51cto.com-t Ype f-mtime +7-exec rm-f {} \; [[Email protected]_web5 ~]# crontab-l# daily 5 o'clock in the morning backup site data 0 5 * * */bin/bash-x/data/code-backup/web_code_backup.sh >/ The effect of Dev/null 2>&1 backup is as follows: [[Email protected]_web5 ~]# Ls/data/code-backup/www.baidu.com/www.baidu.com_ 20180517_174328.TAR.GZ[[EMAIL PROTECTED]_WEB5 ~]# ls/data/code-backup/www.51cto.com/www.51cto.com_20180517_ 174409.TAR.GZ (2) database backup (automatically delete backup files up to 10 days ago) [[[email protected] crontab]# pwd/data/mysql_bakup/crontab[[email protected] crontab]# cat backup_db_ Xiaobaicai.sh#!/bin/bashmysql= "/usr/bin/mysql" mysqldump= "/usr/bin/mysqldump" backup_dir= "/Data/Mysql_Bakup" #DB_ socket= "/var/lib/mysql/mysql.sock" db_hostname= "119.27.184.XX" dbname= "Xiaobaicai" db_user= "Db_xiaobaicai" DB_PASS = "Mhxzk3rfzh" time= ' date +%y%m%d%h%m%s ' lock_file= "${backup_dir}/lock_file.tmp" bkup_log= "/data/mysql_backup/${  Time}_bkup.log "del_bak= ' date-d ' Ten days ago ' +%y%m%d ' # #To judge Lock_fileif [[-F $LOCK _file]];thenexit 255elseecho $$ > $LOCK _filefi# #dump databases# #echo ${time} >> ${bkup_log}echo "=======start bakup============" >>${ Bkup_log}#${mysqldump}-H ${db_hostname}-u${db_user}-p${db_pass}--databases ${dbname} | gzip-9 > ${backup_dir}/${time}.${dbname}.gz${mysqldump}-H ${db_hostname}-u${db_user}-p${db_pass}--databases ${ DBNAME} |gzip-9 > ${backup_dir}/${time}.${dbname}.gzecho "=======finished bakup============" >>${BKUP_LOg}/bin/rm-f ${lock_file}# #del back ten days Before##/bin/rm-f ${backup_dir}/${del_bak}*.gz 

The above backup can also be used in other ways!

Here's how to upload the backup data to the FTP server:

#!/bin/bashftp -n<<!open 119.27.184.84 (连接到FTP服务器)user root root66         (账号密码)binaryhashcd /FTP/Web                (上传到FTP服务器的目录)lcd /www/backup/site     (本地备份数据的目录)promptmput *closebye!

Linux Server build station data backup automatically upload FTP server

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.