自动备份和下载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

AI Hentai Generator
Generate AI Hentai for free.

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

PHP and Flutter are popular technologies for mobile development. Flutter excels in cross-platform capabilities, performance and user interface, and is suitable for applications that require high performance, cross-platform and customized UI. PHP is suitable for server-side applications with lower performance and not cross-platform.

WordPress requires registration. According to my country's "Internet Security Management Measures", websites that provide Internet information services within the country must register with the local provincial Internet Information Office, including WordPress. The registration process includes steps such as selecting a service provider, preparing information, submitting an application, reviewing and publishing, and obtaining a registration number. The benefits of filing include legal compliance, improving credibility, meeting access requirements, ensuring normal access, etc. The filing information must be true and valid, and must be updated regularly after filing.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

WordPress uses MySQL as its article database, its main functions include: storing articles, comments, users and website configuration data. The data tables include: wp_posts (articles), wp_postmeta (metadata), wp_comments (comments), wp_commentmeta (comment metadata), wp_users (users). The database can be accessed and managed via phpMyAdmin or the command line, and it is crucial to back up the database regularly to prevent data loss.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

WordPress search functionality provides users with the convenience of finding content quickly: Location: In the header or top menu Features: Full text search, keyword matching, relevance sorting, fuzzy search Advanced options: Category restrictions, author restrictions, date range, format restrictions Customization: Customize number of results, summary length, matching keyword highlighting

Yes, WordPress is a CMS that allows users to manage websites without coding. However, advanced features and customizations may require some coding knowledge, including themes, plugins, widgets, custom post types, and functions. Code level requirements vary depending on the goals of the implementation, typically no code is required for basic functionality, but basics of HTML, CSS, and PHP are required for advanced customization.
