自动备份和下载WordPress(及MySQL)的fabric脚本_MySQL
WordPress
在一年多之前,我写过一个博客介绍Fabric(Fabric 一个与多台服务器远程交互的Python库和工具),前段时间我也在项目中也大量使用了Fabric来管理很多服务器。
我的博客搭建在一个KVM VPS上,今天也写了一个fabfile来dump数据库、打包WordPress目录,并下载到本地。fabfile代码如下:
#!/usr/bin/python# use Fabric to manage all the hosts in perf env.# usage: fab -f vps_fabfile.py download_backup# author: Jay <smile665> from fabric.context_managers import cd#from fabric.context_managers import settingsfrom fabric.operations import *from fabric.api import *from datetime import datetime env.hosts = 'smilejay.com'env.port = 22env.user = 'root'env.password = '1234'@taskdef download_backup(): # backup my WP file and database, download them to the local machine dt = datetime.now().strftime("%Y-%m-%d-%H-%M-%S") local_dir = '/home/jay/backup' with cd('/tmp'): nginx = '/usr/share/nginx' wp_root = '/usr/share/nginx/html' exclude = 'html/wp-content/cache' bk_name = 'wp_%s.tar.gz' % dt clean = 'rm -f wp*.tar.gz' mysql = 'mysqldump -uroot -p1234 -A > %s/mysql-dump.sql' % wp_root tar = 'tar -zcf %s -C %s html --exclude=%s' % (bk_name, nginx, exclude) run(clean) run(mysql) run(tar) get(bk_name, '%s/%s' % (local_dir, bk_name))</smile665> Copy after login |
Github地址:https://github.com/smilejay/python/blob/master/py2014/vps_fabfile.py
当然,我一般也会使用BackWPup插件来备份WordPress;刚好发现,前段时间使用Nginx替代Apache后,BackWPup运行时仍然要写“/var/www/html/wp-content/backwpup-logs/”目录,所以有个权限问题,最近两个月都是运行失败了。后来对这个目录开放了写权限就没问题了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance >Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

You can view the WordPress front-end by logging into the dashboard and switching to the View Sites tab; automate the viewing process with a headless browser; installing the WordPress plugin to preview the front-end within the dashboard; viewing the front-end via a local URL (if WordPress is set locally).

WordPress IP blocking plugin selection is crucial. The following types can be considered: based on .htaccess: efficient, but complex operation; database operation: flexible, but low efficiency; firewall: high security performance, but complex configuration; self-written: highest control, but requires more technical level.

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.
