如何备份您的WordPress网站

tech2022-07-08  216

This article is part of a series created in partnership with SiteGround. Thank you for supporting the partners who make SitePoint possible.

本文是与SiteGround合作创建的系列文章的一部分。 感谢您支持使SitePoint成为可能的合作伙伴。

Few people care about backups until it’s too late. The question “do we have backups?” is only raised after a catastrophic loss has occurred. Backups are essential. If you fail to prepare then prepare to fail.

很少有人关心备份,直到为时已晚。 问题“我们有备份吗?” 仅在发生灾难性损失后才提高。 备份至关重要 。 如果准备失败,那就准备失败。

Here are five steps to backup success:

以下是成功备份的五个步骤:

Educate your boss/client

教育你的老板/客户

If they understood the technicalities of web development, they wouldn’t need you. Explain the situation in simple monetary terms, e.g. if our server disk crashed today, we could lose everything. It would take M months to rebuild the system at a cost of $X and we could lose $Y in business. A viable backup system would cost $Z to implement and we would be back within N hours. I’m going presume you’ve terrified your boss/client and they’re willing to proceed.

如果他们了解Web开发的技术,则不需要您。 用简单的货币术语解释这种情况,例如,如果今天我们的服务器磁盘崩溃了,我们可能会损失一切。 重建系统需要M个月的时间,成本为$ X,我们的业务可能会损失$ Y。 一个可行的备份系统的实施成本为$ Z,我们将在N小时内返回。 我假设您吓坏了老板/客户,他们愿意继续。

Identify what you need to backup

确定您需要备份的内容

Backing up a WordPress system is a little complex because it depends on specific files and a database. A backup will only be viable if you have up-to-date copies of both.

备份WordPress系统有点复杂,因为它取决于特定的文件和数据库。 只有同时拥有两个副本,备份才可行。

Implement an appropriate backup solution

实施适当的备份解决方案

This will depend on the technologies you’re using and the service you offer. For example, a weekly backup may be suitable for a blog receiving a few updates a month. At worst, you could lose an article or two. A WordPress-powered online shop may need continual backups to ensure customer orders are not be lost.

这将取决于您使用的技术和所提供的服务。 例如,每周备份可能适合每月接收一些更新的博客。 最糟糕的是,您可能会丢失一两篇文章。 由WordPress驱动的在线商店可能需要连续备份,以确保不会丢失客户订单。

Automate!

自动化!

Backups should be taken out of human hands. Consider a system which requires a single click once a day to initiate the backup. You will start with good intentions but it will soon become a chore. What happens when you go on vacation? What if you leave the company? Computers are good at scheduling — let them handle the work.

备份应该从人手中拿出来。 考虑一个每天需要单击一次以启动备份的系统。 您将以良好的意愿开始,但很快就会成为家务。 你去度假怎么办? 如果你离开公司怎么办? 计算机擅长调度-让它们处理工作。

Verify and test your backup

验证并测试您的备份

Your system is only as good as the last successful backup. Ideally, you should automate verification of the backup’s integrity, move backup files off-site, periodically test your restore procedures, and retain previous backups for a reasonable time (three old versions is typical).

您的系统仅与上次成功备份一样好。 理想情况下,您应该自动验证备份的完整性,将备份文件移到异地,定期测试还原过程,并在合理的时间内保留以前的备份(典型的是三个旧版本)。

You can learn more about backing up your WordPress sites manually and easily in the SitePoint’s course How to Secure Your WordPress Site, which you can preview below. For more on WordPress, check out our comprehensive WordPress course on Building Custom WordPress Themes.

您可以在SitePoint的“ 如何保护WordPress网站”课程中了解有关手动和轻松备份WordPress网站的更多信息,您可以在下面进行预览。 有关WordPress的更多信息,请查看我们有关构建自定义WordPress主题的综合WordPress课程。

Loading the player… 正在加载播放器…

WordPress组件 (WordPress Components)

WordPress components have differing backup requirements.

WordPress组件具有不同的备份要求。

WordPress安装文件 (WordPress Installation Files)

You probably downloaded the WordPress installer in an archive from wordpress.org. It includes the following files and folders:

您可能已从wordpress.org的存档中下载了WordPress安装程序。 它包括以下文件和文件夹:

locationdescription/root PHP, readme and licence files/wp-admin/the primary WordPress control panel code/wp-includes/libraries and third-party components/wp-content/themes, plugins and media files 位置 描述 / 根PHP,自述文件和许可证文件 /wp-admin/ 主要的WordPress控制面板代码 /wp-includes/ 库和第三方组件 /wp-content/ 主题,插件和媒体文件

You should never need to backup the default WordPress files. Your code (and third-party plugins) should never modify or add files to /wp-admin/ or /wp-includes/. I recommend retaining a copy of the installer but all versions of WordPress can be downloaded from the release archive. Besides, your installation will eventually receive updates so the live version will be different to the one you downloaded.

您永远不需要备份默认的WordPress文件。 您的代码(和第三方插件)绝对不能修改文件或将文件添加到/wp-admin/或/wp-includes/ 。 我建议保留安装程序的副本,但是可以从发行档案中下载所有版本的WordPress。 此外,您的安装最终将收到更新,因此实时版本将不同于您下载的版本。

根配置文件 (Root Configuration Files)

Several root folder files must be backed-up:

必须备份几个根文件夹文件:

wp-config.php — this contains settings including the database connection strings

wp-config.php它包含设置,包括数据库连接字符串

.htaccess — the server configuration file

.htaccess服务器配置文件

webmaster tool identification files such as googleCODE.html and BingSiteAuth.xml

网站站长工具标识文件,例如google CODE .html和BingSiteAuth.xml

any other files you’ve added

您添加的任何其他文件

In general, you can backup these files once after your installation is complete. However, be wary of themes and plugins which make further changes to the configuration.

通常,安装完成后,您可以备份这些文件一次。 但是,请注意主题和插件,它们会进一步更改配置。

wp-content文件 (wp-content files)

The /wp-content/ folder contains all themes, plugins and media assets such as uploaded images. This folder must be backed-up but it will depend on your development process.

/wp-content/文件夹包含所有主题,插件和媒体资产,例如上载的图像。 必须备份此文件夹,但这取决于您的开发过程。

If you are developing your own custom theme and plugins, it’s beneficial to use a source control system such as Git and create a central repository on GitHub, BitBucket or a similar provider. The source is replicated by these services and on all developer machines; it’s difficult to lose anything so a backup of the /wp-content/themes/ and /wp-content/plugins/ folders may not be absolutely necessary.

如果您正在开发自己的自定义主题和插件,则使用诸如Git之类的源代码控制系统并在GitHub , BitBucket或类似的提供程序上创建中央存储库是有益的。 这些服务在所有开发人员机器上复制源。 丢失任何东西/wp-content/themes/困难,因此不一定绝对需要备份/wp-content/themes/和/wp-content/plugins/文件夹。

However, I suspect most WordPress sites use a combination of third-party themes and plugins with a few custom modifications. In addition, media files are contained in /wp-content/uploads/ or the /wp-content/blogs.dir/ folder on multi-site installations. Therefore, it’s normally easiest to backup everything in the /wp-content/ folder.

但是,我怀疑大多数WordPress网站都结合了第三方主题和带有少量自定义修改的插件。 此外,在多站点安装中,媒体文件包含在/wp-content/uploads/或/wp-content/blogs.dir/文件夹中。 因此,通常最简单的方法是备份/wp-content/文件夹中的所有/wp-content/ 。

The frequency of backups will depend on your update activities. Once every few days is probably adequate for many sites but it may need to be more often when editors regularly add content and images.

备份的频率将取决于您的更新活动。 每隔几天一次对于许多站点可能就足够了,但是当编辑人员定期添加内容和图像时,可能需要更频繁一些。

WordPress数据库 (The WordPress Database)

The database contains all page content, historic revisions, media references, site configurations, theme options, plugin activations, user accounts and more. It’s imperative to backup the database frequently — perhaps once a day for a general blog or every hour for an ecommerce system.

该数据库包含所有页面内容,历史修订,媒体参考,站点配置,主题选项,插件激活,用户帐户等。 必须经常备份数据库-可能是一般博客每天一次或电子商务系统每小时一次。

Be wary that databases can become huge which slows the backup process.

请注意,数据库可能会变得庞大,从而减慢了备份过程。

手动备份 (Manual Backup)

If you don’t have a backup, do it now! I recommend taking a manual backup every so often even if you’ve implemented an automated system — you can never have too many.

如果您没有备份,请立即执行! 我建议即使已经实施了自动化系统, 也应经常进行一次手动备份- 您永远不能拥有太多备份。

Hosts such as SiteGround provide systems like cPanel which allow you to backup all files, databases and settings. Search for backup or the backup wizard and follow the steps. These generally create a file which can be restored in the same system.

诸如SiteGround之类的主机提供了诸如cPanel之类的系统,该系统使您可以备份所有文件,数据库和设置。 搜索备份或备份向导,然后执行以下步骤。 这些通常会创建一个可以在同一系统中还原的文件。

If you prefer a more hands-on approach:

如果您更喜欢动手做方法:

Download the root configuration and /wp-content/ files using FTP, SCP, wget or any other tool you have to hand.

使用FTP, SCP , wget或您必须使用的任何其他工具下载根配置和/wp-content/文件。

Download a shapshot of the database which contains the SQL commands to recreate tables and populate the data.

下载包含SQL命令的数据库快照,以重新创建表并填充数据。

Most hosts provide SQL tools such as phpMyAdmin or Adminer or you can install them yourself on any hosting which supports PHP. To log in, you will require:

大多数主机都提供SQL工具,例如phpMyAdmin或Adminer,或者您可以将它们自己安装在任何支持PHP的主机上。 要登录,您将需要:

the host name — it’s normally localhost but check the DB_HOST setting in wp-config.php

主机名-通常是localhost但请检查wp-config.php的DB_HOST设置

the database name — see DB_NAME in wp-config.php

数据库名称-请参阅wp-config.php DB_NAME

a database user’s name — see DB_USER in wp-config.php, and

数据库用户名—请参阅wp-config.php DB_USER ,以及

the database user’s password — see DB_PASSWORD in wp-config.php.

数据库用户的密码-请参阅wp-config.php DB_PASSWORD 。

You should see many tables such as wp_posts, wp_users and wp_comments once you have connected successfully. (Note the table prefix is set by $table_prefix in wp-config.php and may not always be wp_.)

成功连接后,您应该看到许多表,例如wp_posts , wp_users和wp_comments 。 (请注意,表前缀由wp-config.php的$table_prefix设置,可能并不总是wp_ 。)

Look for an option such as dump, export or backup. Ensure every table (with drop and create) and all data is selected before downloading the SQL file.

查找诸如转储 , 导出或备份之类的选项。 在下载SQL文件之前,请确保已选择每个表(带有drop和create)以及所有数据。

Command line ninjas with SSH access can backup a database using the mysqldump command:

具有SSH访问权限的命令行忍者可以使用mysqldump命令备份数据库:

mysqldump --host=hostname --user=dbuser --password=dbpass --add-drop-table --result-file=backup.sql dbname

where hostname, dbname, dbuser and dbpass are the credentials we specified above. A full backup will be output to the backup.sql file in the current folder which can be downloaded.

其中hostname , dbname , dbuser和dbpass是我们上面指定的凭据。 完整备份将输出到当前文件夹中的backup.sql文件中,可以下载该文件。

Restoring your manual backup is matter of uploading the files to the correct location and importing the MySQL data using a SQL tool or the command:

恢复手动备份只需将文件上传到正确的位置,然后使用SQL工具或以下命令导入MySQL数据即可:

mysql --host=hostname --user=dbuser --password=dbpass dbname < backup.sql

All manual backup processes can be automated using tools such as cron which can also be controlled via cPanel.

可以使用诸如cron之类的工具来自动执行所有手动备份过程,这些工具也可以通过cPanel进行控制。

备份插件 (Backup Plugins)

Fortunately, there are dozens of WordPress backup plugins to choose from which can automate your process and export backups to an off-site data store. The most popular include:

幸运的是, 有数十个WordPress备份插件可供选择,它们可以自动执行流程并将备份导出到异地数据存储。 最受欢迎的包括:

喷气背包 (Jetpack)

The closest option to an official plugin, Jetpack provides a range of SEO, security and site management features which include real-time backups to unlimited storage space on the professional paid plan.

与官方插件最接近的选项是Jetpack,它提供了一系列SEO,安全性和站点管理功能,其中包括实时备份到专业付费计划中无限的存储空间。

UdraftPlus (UdraftPlus)

One of the highest-ranking backup plugins with more than one million active installations, UdraftPlus schedules and stores backups on remote systems such as Dropbox, Google Drive, OneDrive, Amazon S3, or your own server.

UdraftPlus是级别最高的备份插件之一,具有超过一百万的活动安装,它可以计划备份并将备份存储在Dropbox,Google Drive,OneDrive,Amazon S3或您自己的服务器等远程系统上。

备份WordPress (BackUpWordPress)

A simple plugin which backs up your database and files on a schedule to suit your requirements. The commercial edition enables off-site cloud storage backups.

一个简单的插件,可以根据您的计划备份您的数据库和文件。 商业版支持异地云存储备份。

后退WPup (BackWPup)

The free edition of BackWPup allows you to backup your files and database to a variety of your own and third-party storage spaces. The commercial editon provides scheduling, differential backup and automatic updates.

BackWPup的免费版本使您可以将文件和数据库备份到各种自己的存储空间和第三方存储空间。 商业版本提供调度,差异备份和自动更新。

复印机 (Duplicator)

Duplicator is often used for migration and cloning but also provides manual backup and restore facilities. The commercial edition supports scheduling and cloud backups.

复制器通常用于迁移和克隆,但也提供手动备份和还原功能。 商业版支持计划和云备份。

XCloner (XCloner)

An open source plugin which provides a range of scheduling and cloud storage options.

一个开源插件,提供一系列计划和云存储选项。

备份服务 (Backup Services)

Alternatively, you can choose a third-party service to manage your WordPress backups. Hosts such as SiteGround are the best place to start; they can implement backup options for all hosting plans. SiteGround even has an in-house backup service that automatically saves the latest 30 copies of your site and lets you restore the one you need on demand.

或者,您可以选择第三方服务来管理WordPress备份。 像SiteGround这样的主机是最好的起点。 他们可以为所有托管计划实施备份选项。 SiteGround甚至具有内部备份服务,该服务可自动保存您网站的最新30个副本,并允许您按需还原所需的副本。

Further services include:

其他服务包括:

VaultPress (VaultPress)

VaultPress uses Jetpack to store daily or real-time automated backups off-site as well as scanning for malicious software, spammer attacks and hosting failures. Plans start from $3.50 per month.

VaultPress使用Jetpack在站点外存储每日或实时自动备份,以及扫描恶意软件,垃圾邮件发送者攻击和托管故障。 计划每月3.50美元起。

WP时间胶囊 (WP Time Capsule)

WP Time Capsule takes incremental backups; only changed files and data are backed-up so the process is considerably faster than those which backup everything. An automatic backup is taken prior to every WordPress update. The Lite plan costs nothing for daily backups and 15-day restore points.

WP Time Capsule进行增量备份; 仅备份已更改的文件和数据,因此该过程比备份所有文件和数据的过程要快得多。 在每次WordPress更新之前都会进行一次自动备份。 Lite计划的每日备份和15天还原点不花任何费用。

管理WP (Manage WP)

Manage WP has facilities to help you manage multiple WordPress installations. Premium plans start from $2 per website per month and include an incremental backup which can be scheduled to every hour. Further features include performance monitoring, security checks, analytics and reporting.

Manage WP具有帮助您管理多个WordPress安装的功能。 高级计划的费用为每个网站每月2美元,其中包括可以安排到每小时的增量备份。 其他功能包括性能监视,安全检查,分析和报告。

今天备份! (Backup Today!)

WordPress backups can be more complex than other software but the range of tools, plugins and services simplify the process. If you don’t have a backup procedure, take a snapshot now and investigate the options. Every minute you delay increases the risk of catastrophic failure.

WordPress备份可能比其他软件更复杂,但是一系列工具,插件和服务简化了该过程。 如果没有备份过程,请立即拍摄快照并研究选项。 您延迟的每一分钟都会增加灾难性故障的风险。

翻译自: https://www.sitepoint.com/backup-wordpress-site/

最新回复(0)