Support #18982 » back-up-production-site.sh
1 |
#!/bin/bash
|
---|---|
2 |
|
3 |
# Check if a parameter was provided
|
4 |
if [ -z "$1" ]; then |
5 |
echo "Error: No number provided. Please provide a number as a parameter." |
6 |
exit 1
|
7 |
fi
|
8 |
|
9 |
# Assign the parameter to a variable
|
10 |
number=$1 |
11 |
|
12 |
# Database details
|
13 |
database="commons_wp" |
14 |
# Ensure your .my.cnf file is set up for passwordless access
|
15 |
|
16 |
# Directory for backups
|
17 |
backup_dir=~/data-restore-2023-10-11/production-backups |
18 |
files_backup_dir=${backup_dir}/files/${number} |
19 |
|
20 |
# Source directory for files
|
21 |
source_dir=/PROD_WWW/html/commons/www/wp-content/blogs.dir/${number}/ |
22 |
|
23 |
# Create the directories if they don't exist
|
24 |
mkdir -p "$backup_dir" |
25 |
mkdir -p "$files_backup_dir" |
26 |
|
27 |
# Rsync files from source to backup directory
|
28 |
rsync -avzh --progress "${source_dir}" "${files_backup_dir}" |
29 |
|
30 |
# Get the list of tables like 'wp_{number}_%'
|
31 |
tables=$(mysql -D "$database" -e "SHOW TABLES LIKE 'wp\_${number}\_%';" | awk '{ print $1 }' | grep -v '^Tables' | tr '\n' ' ') |
32 |
|
33 |
# Check if tables were found
|
34 |
if [ -z "$tables" ]; then |
35 |
echo "No tables found for the provided number: $number" |
36 |
exit 1
|
37 |
fi
|
38 |
|
39 |
# Dump the tables
|
40 |
mysqldump "$database" $tables > "${backup_dir}/wp_${number}_backup.sql" |
41 |
|
42 |
# Check if the mysqldump was successful
|
43 |
if [ $? -eq 0 ]; then |
44 |
echo "Backup successful. Files and database backup created in ${backup_dir}" |
45 |
else
|
46 |
echo "Database backup failed." |
47 |
fi
|
48 |
|
- « Previous
- 1
- 2
- 3
- Next »