-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
96 lines (78 loc) · 4.82 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<project name="WordpressBackup" default="help" basedir=".">
<!-- the default Help target -->
<target name="help">
<echo>Wordpress BackUp Tool
Before backing up your blog, you need to create a file called 'backup.properties' with some attributes. For help on how to create this file, type
$> ant properties
With a 'backup.properties' file created, you can backup your blog by typing
$> ant backup
If you want to use a file with a different name than 'backup.properties', you may use a custom one by typing
$> ant -Dproperties=custom_properties_file backup
</echo>
</target>
<!-- the properties help target -->
<target name="properties">
<echo>Attributes of the properties file:
- server.host: the host address/IP where your wordpress installation is running
- server.username: the username used to connect to the above server
- server.passphrase: the password to connect to the server through SSH. Note: avoid using it, because you will need to save the password in a text file, and others may read it!
- server.keyfile: the path to a private key file that can be used to connect to that server
- wordpress.dir: the directory where the wordpress is installed (this directory contains a wp-config.php file)
- db.address: the address/IP of the MySql server. "localhost" for most cases.
- db.name: the database name used by the MySql installation
- db.username: the username used to connect to the database
- db.password: the password used to connect to the database
- backup.name: a string that will be used to name your backups. Default is 'wordpress_backup'
- backup.remotedir: the directory where the backups will be saved on the remote server. If not set, the backup will not be kept in the remote server, and a temporary directory will be used.
- backup.localdir: the directory in the local machine where the backups will be saved. Default is the current directory.</echo>
</target>
<!-- the actual backup target -->
<target name="backup">
<condition property="properties" value="backup.properties">
<not><isset property="properties"/></not>
</condition>
<property file="${properties}"/>
<tstamp><format property="backup.timestamp" pattern="yyyy-MM-dd_HH-mm" /></tstamp>
<condition property="backup.name" value="wordpress_backup">
<not><isset property="backup.name"/></not>
</condition>
<condition property="backup.keepremote" value="true">
<isset property="backup.remotedir"/>
</condition>
<condition property="backup.keepremote" value="false">
<not><isset property="backup.remotedir"/></not>
</condition>
<condition property="backup.remotedir" value="/tmp/${backup.name}_${backup.timestamp}">
<not><isset property="backup.remotedir"/></not>
</condition>
<condition property="backup.localdir" value="${basedir}">
<not><isset property="backup.localdir"/></not>
</condition>
<condition property="server.passphrase" value="">
<not><isset property="server.passphrase"/></not>
</condition>
<property name="backup.remotedirtmp" value="${backup.remotedir}/${backup.timestamp}"/>
<property name="backup.sqlname" value="${db.name}_${backup.timestamp}.sql"/>
<property name="backup.wordpres" value="${backup.remotedirtmp}/wordpress"/>
<property name="backup.filename" value="${backup.remotedir}/${backup.name}_${backup.timestamp}.zip"/>
<mkdir dir="${backup.localdir}"/>
<sshexec
host="${server.host}" username="${server.username}"
keyfile="${server.keyfile}" passphrase="${server.passphrase}" trust="true"
command="
mkdir -p "${backup.remotedirtmp}";
mysqldump -h ${db.address} -u ${db.username} -p${db.password} --result-file="${backup.remotedirtmp}/${backup.sqlname}" ${db.name};
cp -r "${wordpress.dir}" "${backup.wordpres}";
cd "${backup.remotedirtmp}";
zip -9 -q -r -T "${backup.filename}" "${backup.sqlname}" wordpress;
rm -r "${backup.remotedirtmp}";"/>
<scp
host="${server.host}" username="${server.username}"
keyfile="${server.keyfile}" passphrase="${server.passphrase}" trust="true"
file="${server.username}@${server.host}:${backup.filename}" localTodir="${backup.localdir}"/>
<sshexec
host="${server.host}" username="${server.username}"
keyfile="${server.keyfile}" passphrase="${server.passphrase}" trust="true"
command="if ! ${backup.keepremote} ; then rm -r "${backup.remotedir}"; fi"/>
</target>
</project>