View difference between Paste ID: qEVG4H6f and nZ2fiL8j
SHOW: | | - or go back to the newest paste.
1
#!/bin/bash
2
3-
# wordpress-auto-backup.sh
3+
4
# 1/ You can do SSH password-less login to the server
5
#	How : https://easyengine.io/tutorials/linux/passwordless-authentication-ssh/
6
# 2/ You have created a correct ~/.my.cnf file
7-
#   How : https://easyengine.io/tutorials/linux/passwordless-authentication-ssh/
7+
#	How : https://easyengine.io/tutorials/mysql/mycnf-preference/
8
9-
#   How : https://easyengine.io/tutorials/mysql/mycnf-preference/
9+
[email protected] 
10
wordpress_location=/home/MyUser/MyWebsite
11-
### RUNTIME PARAMETERS
11+
backup_location=/MyDisk/MyBackup
12-
# wordpress-auto-backup.sh  <server address> <home directory> <backup directory>
12+
13
mysql_server=mysql.MyWebsite.com
14-
### HOW IT WORKS 
14+
mysql_database=MyDatabase_db
15-
# 1/ SSH to server
15+
16-
# 2/ read wp-config file & get details
16+
# ====== START BACKUP ============
17-
# 3/ create backup_dir/web
17+
18-
# 4/ rsync home_dir backup_dir/web 
18+
19-
# 5/ backup database to backup_dir/web/today.mysql
19+
20-
# 6/ compress backup_dir/web to backup_dir/backup_today.bz2 
20+
21
ssh  $wordpress_server "mysqldump -h $mysql_server $mysql_database > $wordpress_location/db-$today.mysql"
22-
### choose backup retention
22+
ssh  $wordpress_server "gzip $wordpress_location/db-$today.mysql"
23-
# backup retention: weekly
23+
24
# download everything 
25-
# backup retention: monthly
25+
rsync -avuz $wordpress_server:$wordpress_location/* $backup_location/
26-
#today=`date +%d`
26+
27
# delete database backup
28-
timestamp=`date +%H-%M-%S`
28+
# so no one can download it via the website
29
ssh $wordpress_server "rm $wordpress_location/db-$today.mysql.gz"
30-
compressor1='gzip'
30+
31-
compressor2='pbzip2'
31+
# done !