Backup WordPress to Version Control Automatically

I migrated my WordPress blog to a VPS hosting recently, and after that, the first thing that came to my mind was: Backup.

There were a lot of similar posts on the Internet, but what I found was not good enough for me, so I wrote what I did in this article to help people who want to do the similar things. It would be great if you have better ideas and please feel free to let me know.

The following scripts had been tested on: Ubuntu 13.04 and MySQL 5.5. The directory and scripts may need to be changed for different Linux distributions.

The Problem

First, we need to answer the questions: what do we want to backup, what do not, and where to save the backup.

What do we want to backup? everything not from the setup, which includes:

  • Posts, Pages and Comments. They are the most important things that we want to backup.
  • Uploaded Media Files. They are the same important with the posts/pages.
  • The Installed Themes and Plugins. I don’t want to search, install, and customize them again, especially the colors.

Ok, that’s sounds reasonable, but is there anything you don’t want to backup? Continue reading “Backup WordPress to Version Control Automatically”

集成ACEGI 进行权限控制

一. 简单介绍

1.1 本文目的

集成Acegi到自己的项目中, 并且将用户信息和权限放到数据库, 提供方法允许权限动态变化,变化后自动加载最新的权限

本文介绍Acegi例子的时候采用的是acegi-security-samples-tutorial-1.0.6.war

阅读本文需要对Spring有一定的了解, 如果你还没有接触过, 有些地方可能不容易理解, 这时候可能需要参考本文后附的Spring地址, 先了解一下Spring的基本知识.

本文使用的是Mysql数据库, 如果你使用其他的数据库, 可能需要修改相应的SQL.

本文及所附的全部代码放在http://acegi-test.sourceforge.net/

1.2 安装与配置

项目主页: http://www.acegisecurity.org/
Continue reading “集成ACEGI 进行权限控制”

How To: using bash script to backup MySql

Create a file backup_db.sh, and paste the following contents:

#get the first parameter as the database name
DATABASE=$1

#if no database specified, then you can set the default one
if [ -z $DATABASE ]; then
    DATABASE=default_database_name_here
fi

#mysql user and password to backup the database.
MYSQLUSER=mysql_user
MYSQLPWD=mysql_password
    
#path to backup
ARCHIVEPATH=~/backup/db_backup
DATE=`date +%Y%m%d`
YEAR=`date +%Y`
MONTH=`date +%m`
FOLDER_MONTH=$ARCHIVEPATH/$YEAR$MONTH
    
if [ ! -d $FOLDER_MONTH ]; then
    echo "mkdir $FOLDER_MONTH"
    mkdir $FOLDER_MONTH
fi
    
# Backup
echo "mysqldump -u$MYSQLUSER -p$MYSQLPWD $DATABASE | gzip $FOLDER_MONTH/$DATABASE-$DATE.sql.gz"
mysqldump -u$MYSQLUSER -p$MYSQLPWD $DATABASE | gzip $FOLDER_MONTH/$DATABASE-$DATE.sql.gz

and you can add the script to cron job under *nix and schedule under windows:

*nix:

Save the following text in file: db_backup.at

10 * * * * ~/backup/backup_db.sh databasename

and call

crontab db_backup.at

You need to change the period to run the script for your business, e.g. each day, each week etc.

How To: Enable Mysql binary log

#server-id       = 1
log-bin         = /var/log/mysql/mysql-bin.log

#if you set the expire_logs_days = x var in the [mysqld] section of your my.cnf it will automatically rotate your bin logs after x days.
expire_logs_days = 30

#it will create a new log file when the current file reach the specified size.
max_binlog_size = 100M