Building a high-security e-commerce website (automatic local/remote dual-backup of website files and databases) [connected E-commerce system architecture]

Source: Internet
Author: User

Building a high-security e-commerce website (automatic local/remote dual-backup of website files and databases) [connected E-commerce system architecture]Source:Http://jimmyli.blog.51cto.com/I'm standing on the shoulders of giants, Jimmy Li
By Jimmy Li
Keywords: website, e-commerce, Shell, automatic backup, remote backup
------ [Connected E-commerce system architecture] technical architecture of e-commerce websites with more than 1 million visits
Connection:
Http://jimmyli.blog.51cto.com/3190309/584992Website O & M remote backup solution and fault emergency backup mirror Station
The previous article details server security. Next, we will continue to introduce the E-commerce system architecture related to Linux Server File backup, database backup, and data security storage. There are a variety of security solutions, data backup is the top priority. E-commerce websites pay more attention to data security and data backup solutions, including local backup and remote backup architectures. There are many backup solutions for Linux servers. This article introduces a popular and suitable solution to complete automatic backup by writing Shell scripts. This architecture includes backing up website files and databases, automatically backing up local data, uploading backup scripts over FTP, and completing local backup and remote backup to implement a dual-layer backup solution. Key points of this article:


1. Fully automated backup of website files and databases.
2. Write a Shell script to complete automatic backup.
3. both local and remote backup and FTP backup are performed simultaneously.
4. backup solution for Linux servers.
5. This includes backing up website files, website program files, data files, and MYSQL databases.
6. Regular and scheduled backups are automatically completed. Regular deletion of old backup. Here, the backup is automatically deleted 30 days ago, and the backup space is reused.

Directory:
I. Preparations
Ii. Architecture diagram of building a high-security e-commerce website (automatic local/remote dual-backup of website files and databases)
Iii. Automatic local backup of websites and databases and FTP upload of the backup Shell script to complete the instance; detailed explanation and comment on the backup script.
At the beginning of the e-commerce website in operation, we have been reiterated that we must back up our own data, because too much uncertainty may cause database loss, in addition, most basic service providers cannot provide daily backup data. Previously, this BLOG provided a backup method, just to mention it a bit, some new users may not be very good at starting. Today I will share my own backup script.
For details, see the appendix http://jimmyli.blog.51cto.com/3190309/584992 "website O & M remote backup solution and fault emergency backup mirror station"
  I. preparations:
1. Software Installation
Lftp needs to be installed on the Linux server in advance, and the lftp function is relatively powerful. CentOS directly runs: yum install lftp, and Debian executes: apt-get install lftp.
2. Create a backup directory
You need to create the/home/backup/directory on the Linux server.
3. ftp remote backup ip account password
You need to create a backup directory on the remote FTP. If there are not many databases on the Linux server, you can use the storage space of the basic network service provider. You can also use a dedicated backup server. It can be flexibly controlled based on the application size, data size, network conditions, and actual network resources and hardware resources. Ii. Architecture diagram of building a high-security e-commerce website (automatic local/remote dual-backup of website files and databases)650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131227/0P354C05-0.jpg "/>
Iii. Automatic local backup of websites and databases and FTP upload of backup Shell scripts Complete instance:
========================================================== ======================================
Shell
  1. #! /Bin/bash
  2. # Funciont: Backup website and mysql database
  3. # Author: Jimmy Li
  4. # Website: http://jimmyli.blog.51cto.com/
  5. # IMPORTANT !!! Please Setting the following Values!
  6. Backup_Dir1 =/data/wwwroot/jimmyli.blog.51cto.com
  7. MYSQL_UserName = root
  8. MYSQL_PassWord = Your mysql Database root Password
  9. Backup_Database_Name1 = jimmyli.blog.51cto.com
  10. FTP_HostName = jimmyli.blog.51cto.com
  11. FTP_UserName = jimmyli.blog.51cto.com
  12. FTP_PassWord = jimmyli.blog.51cto.com
  13. FTP_BackupDir = jimmyli.blog.51cto.com -- backup
  14. TodayWWWBackup = www-*-$ (date + "% Y % m % d" 2.16.tar.gz
  15. TodayDBBackup = db-*-$ (date + "% Y % m % d"). SQL
  16. OldWWWBackup = www-*-$ (date-d-30day + "% Y % m % d" 2.16.tar.gz
  17. OldDBBackup = db-*-$ (date-d-30day + "% Y % m % d"). SQL
  18. Tar zcf/home/backup/www-$ Backup_Dir1-$ (date + "% Y % m % d" 2.16.tar.gz-C/home/wwwroot/$ Backup_Dir1 -- exclude = soft
  19. /Usr/local/mysql/bin/mysqldump-u $ MYSQL_UserName-p $ MYSQL_PassWord $ Backup_Database_Name1>/home/backup/db-$ Backup_Database_Name1-$ (date + "% Y % m % d "). SQL
  20. Rm $ OldWWWBackup
  21. Rm $ OldDBBackup
  22. Cd/home/backup/
  23. Lftp $ FTP_HostName-u $ FTP_UserName, $ FTP_PassWord <EOF
  24. Cd $ FTP_BackupDir
  25. Mrm $ OldWWWBackup
  26. Mrm $ OldDBBackup
  27. Mput $ TodayWWWBackup
  28. Mput $ TodayDBBackup
  29. Bye
  30. EOF

 
========================================================== ======================================
The following describes the backup script in detail. Note:
#! /Bin/bash
# Funciont: Backup website and mysql database
# Author: Jimmy Li
# Website: http://jimmyli.blog.51cto.com/
# IMPORTANT !!! Please Setting the following Values! ######~ Set Directory you want to backup ~ ###### Change the following directory to the directory you want to back up. Generally, all directories under/data/wwwroot/are directly written to be backed up. You can add more: Backup_Dir2 = your directory, and the numbers following Backup_Dir increase sequentially. If there are less than N, you can directly Delete unnecessary ones and modify the tar zcf section below. Backup_Dir1 =/data/wwwroot/jimmyli.blog.51cto.com
######~ Set MySQL UserName and password ~ ###### Set the MySQL user name and password, preferably root. Other users may be unable to export some databases due to permission issues.
MYSQL_UserName = root
MYSQL_PassWord = Your mysql Database root Password ######~ Set MySQL Database you want to backup ~ ###### Set the database to be partially added: Backup_Database_Name2 = database name. The numbers following Backup_Database_Name increase sequentially.
Backup_Database_Name1 = jimmyli.blog.51cto.com
######~ Set FTP Information ~ ###### Set FTP information for storing backup data
FTP_HostName = jimmyli.blog.51cto.com // IP address or domain name of the FTP server
FTP_UserName = jimmyli.blog.51cto.com // FTP Server Username
FTP_PassWord = jimmyli.blog.51cto.com // password of the FTP server user
FTP_BackupDir = jimmyli.blog.51cto.com -- backup // back up data to the FTP directory, which must be created in advance. # Values Setting END! ###### Set end TodayWWWBackup = www-*-$ (date + "% Y % m % d" ).tar.gz
TodayDBBackup = db-*-$ (date + "% Y % m % d"). SQL
OldWWWBackup = www-*-$ (date-d-30day + "% Y % m % d" 2.16.tar.gz
OldDBBackup = db-*-$ (date-d-30day + "% Y % m % d "). sqltar zcf/home/backup/www-$ Backup_Dir1-$ (date + "% Y % m % d" 2.16.tar.gz-C/home/wwwroot/$ Backup_Dir1 -- exclude = soft
### The preceding section backs up website file data because my website is scattered and some directories under the website directory are temporary directories and do not need to be backed up, therefore, you can add -- exclude = non-Backup Directory. If Backup_Dir2 = yourdir is added, add tar zcf/home/backup/www-$ Backup_Dir2-$ (date + "% Y % m % d" 2.16.tar.gz-C
/Home/wwwroot/$ Backup_Dir2. If redundant, delete the redundant rows. /Usr/local/mysql/bin/mysqldump-u $ MYSQL_UserName-p $ MYSQL_PassWord $ Backup_Database_Name1>/home/backup/db-$ Backup_Database_Name1-$ (date + "% Y % m % d "). SQL
### Back up the MySQL database. If Backup_Database_Name2 = yourdatabasename is added to the front, add/usr/local/mysql/bin/mysqldump-u $ MYSQL_UserName-p $ MYSQL_PassWord $ Backup_Database_Name2>/home/backup/db-$ Backup_Database_Name2-$ (date + "% Y "% m % d "). SQL. If redundant, delete the redundant rows. Rm $ OldWWWBackup
Rm $ OldDBBackup
### Delete backups 30 days ago ### cd/home/backup/### the following section describes automatic upload. I have to say that lftp is very powerful. Abandon ftp ####
Lftp $ FTP_HostName-u $ FTP_UserName, $ FTP_PassWord <EOF
Cd $ FTP_BackupDir
Mrm $ OldWWWBackup
Mrm $ OldDBBackup
Mput $ TodayWWWBackup
Mput $ TodayDBBackup
Bye
EOF Script: Download the script, put the script under/root/, modify the parameters in the script according to the above annotation, and save the script. If you are not familiar with vim or nano Editor, use winscp to execute: chmod + x/root/backup. sh adds the execution permission for the script. Run: crontab-e to add scheduled execution. Add: 0 3 ***/root/backup to crontab. sh is automatically executed at AM/root/bakcup. sh script to back up data on the Linux server and upload it to the preset remote FTP.
Back up your website at because the website traffic during this period is the lowest. That is to say, backup is performed when few people access it. Appendix: Website O & M remote backup solution and fault emergency backup mirror Station
650) this. width = 650; "onload =" if (this. width/& gt; 650) this. width = 650; "style =" behavior: none "border =" 0 "alt =" "isimg =" false "src =" http://www.bkjia.com/uploads/allimg/131227/0P3543D5-1.gif "/> Enable emergency Web service when remote backup fault emergency is regularly checked
Connection: Http://jimmyli.blog.51cto.com/3190309/584992 Website O & M remote backup solution and fault emergency backup mirror Station
Source: http://jimmyli.blog.51cto.com/Jimmy Li Blog. You are welcome to discuss and communicate with each other. Deduction: ⑥ ()

This article is from the "Jimmy Li I stand on the shoulders of giants" blog, please be sure to keep this source http://jimmyli.blog.51cto.com/3190309/691069

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.