-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest-run-backup.sh
executable file
·165 lines (139 loc) · 5.18 KB
/
test-run-backup.sh
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env bash
# ----------------------------------------------------------------------
#
# Backup Script for Wordpress Database
#
# Developed by Evert Ramos
#
# This script is meant to be used with the repo:
#
# > https://github.com/evertramos/docker-wordpress-letsencrypt
#
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# We will comment these next lines in order to treat all errors in the
# script exiting in case of failure
# ----------------------------------------------------------------------
# Basic bash settings - Careful with that!
#if test "$BASH" = "" || "$BASH" -uc 'a=();true "${a[@]}"' 2>/dev/null; then
# # Bash 4.4, Zsh
# set -euo pipefail
#else
# # Bash 4.3 and older chokes on empty arrays with set -u.
# set -eo pipefail
#fi
shopt -s nullglob globstar
# Get the sript file real path
SCRIPT_PATH="$(dirname "$(readlink -f "$0")")"
# Read all functions and files in base folder
source $SCRIPT_PATH"/base/bootstrap.sh"
# ---------------------------------------------------------------------
#
# Function to call other functions and output messages from the script
#
# ---------------------------------------------------------------------
run_function() {
echo "${yellow}[start]--------------------------------------------------${reset}"
# Call the specified function
if [ -n "$(type -t "$1")" ] && [ "$(type -t "$1")" = function ]; then
echo "${cyan}...running function \"${1}\" to:${reset}"
if [ ! -z $2 ]; then
$1 $2
else
$1
fi
else
echo "${red}>>> -----------------------------------------------------${reset}"
echo "${red}>>>${reset}"
echo "${red}>>>[ERROR] Function \"$1\" not found!${reset}"
echo "${red}>>>${reset}"
echo "${red}>>> -----------------------------------------------------${reset}"
echo "${yellow}[ended with ${red}[ERROR]${yellow}]-------------------------------------${reset}"
exit 1
fi
# Show result from the function execution
if [ $? -ne 0 ]; then
echo "${red}>>> -----------------------------------------------------${reset}"
echo "${red}>>>${reset}"
echo "${red}>>> Ups! Something went wrong...${reset}"
echo "${red}>>>${reset}"
echo "${red}>>> ${MESSAGE}${reset}"
echo "${red}>>>${reset}"
echo "${red}>>> -----------------------------------------------------${reset}"
echo "${yellow}[ended with ${red}ERROR${yellow}/WARNING ($?)----------------------------${reset}"
exit 1
else
echo "${green}>>> Success!${reset}"
fi
echo "${yellow}[end]----------------------------------------------------${reset}"
echo
}
# ---------------------------------------------------------------------
#
# Function for this script
#
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
#
# Setting '.env' file location for the docker-wordpress-letsnecrypt
#
# ---------------------------------------------------------------------
ENV_FILE_LOCATION=./../compose
# Symlink '.env' file to local folder
run_function symlink_env_file
# Read '.env' file from compose folder
run_function check_env_file
# Check if script is already running
save_pid
trap 'delete_pid' EXIT SIGQUIT SIGINT SIGSTOP SIGTERM ERR
# Check Server Capacity
#run_function check_ram_memory
#run_function check_disk_space
# Clean up old backup if needed
source $SCRIPT_PATH/clean-backup.sh
# ---------------------------------------------------------------------
#
# Backup Location Settings
#
# ---------------------------------------------------------------------
# Please note that the basic configuration sets the backup on the folder outside
# the compose folder for docker-wordpress-letsencrypt
#
# If you want to set your own location please update your .env file accordingly
# ----------------------------------------------------------------------
BACKUP_PATH=$BACKUP_PATH_NAME
# ----------------------------------------------------------------------
# Long Term Backup
# ----------------------------------------------------------------------
LONG_TERM_BACKUP=false
if [ ! -z "$BACKUP_LONG_TERM_PATH_NAME" ] && [ ! -z "$BACKUP_LONG_TERM_RETENTION" ] && [ ! -z $1 ]; then
echo
echo "Running a long term backup!"
echo
LONG_TERM_BACKUP=true
BACKUP_PATH=$BACKUP_PATH"/"$BACKUP_LONG_TERM_PATH_NAME
# run_function clean_backup_long_term
fi
# Backup Database
# Set the first parameter as the subfolder name
#if [ -z ${DB_BACKUP_PATH_NAME+X} ]; then
# run_function backup_database
#else
# run_function backup_database $DB_BACKUP_PATH_NAME
#fi
# Compress file (database)
#run_function compress_file $BACKUP_FILE
# Backup wp-content
# Set the first parameter as the subfolder name
#if [ -z ${WP_BACKUP_PATH_NAME+X} ]; then
# run_function backup_wp_content
#else
# run_function backup_wp_content $WP_BACKUP_PATH_NAME
#fi
# Compress file (database)
#run_function compress_file $BACKUP_FILE
# Run Extra Scripts if exists
if [ -e $SCRIPT_PATH"/extra-script.sh" ]; then
source $SCRIPT_PATH/extra-script.sh
fi
exit 0