我的博客搭建在一个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@gmail.com> from fabric.context_managers import cd #from fabric.context_managers import settings from fabric.operations import * from fabric.api import * from datetime import datetime env.hosts = 'smilejay.com' env.port = 22 env.user = 'root' env.password = '1234' @task def 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)) |
Github地址:https://github.com/smilejay/python/blob/master/py2014/vps_fabfile.py
当然,我一般也会使用BackWPup插件来备份WordPress;刚好发现,前段时间使用Nginx替代Apache后,BackWPup运行时仍然要写“/var/www/html/wp-content/backwpup-logs/”目录,所以有个权限问题,最近两个月都是运行失败了。后来对这个目录开放了写权限就没问题了。
时间: 2024-09-27 19:59:10