-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame-server-backup.sh
executable file
·177 lines (177 loc) · 5.31 KB
/
game-server-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
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
#
# ----------------------------------------------------------------------------
# 7-zip backup(s), using pre-configured include and exclude files ...
# ============================================================================
# Created: 2024-03-06, by [email protected]
# Last modified: 2024-06-13, by [email protected]
# ----------------------------------------------------------------------------
#
# Accepts multiple server/backup identifier(s) in the same command-line.
#
# Usage / command-line parameters:
#
# gameserverid
#
# The game-server/backup-config identifier(s) to backup.
#
# Example:
#
# ./game-server-stop.sh backupconfigid1 backupconfigid2 backupconfigidN;
#
# ----------------------------------------------------------------------------
#
# Figure-out where the scripts folder is located ...
#
SCRIPTS_FOLDER="$( dirname -- "$( readlink -f -- "$0"; )"; )";
#
# Include the base script dependancies ...
#
source $SCRIPTS_FOLDER/include/include-base.inc;
#
# Process command-line parameters ...
#
# Check how many parameters were passed ...
#
GAMESERVERIDCOUNT="$#";
if [ $GAMESERVERIDCOUNT -lt 1 ]; then
MESSAGE="${ANSI_REDLT}$(figlet "Error:")${ANSI_OFF}\n";
MESSAGE+="${ANSI_WHITE}At least one (1) gameserverid must be specified!${ANSI_OFF}";
echo -e "$MESSAGE";
if [[ $SCRIPT_LOG_FILE ]]; then
echo -e "$MESSAGE" | ansi2txt >> "$SCRIPT_LOG_FILE";
fi;
#
# Display end of stuff ...
#
source $SCRIPTS_FOLDER/include/include-outputend.inc;
exit 1;
fi;
#
# Loop throuch each gameserverid and process it ...
#
while [ $# -gt 0 ]; do
#
# Set gameserverid to current parameter ...
#
GAMESERVERID=$1;
#
# Determine script log file ...
#
SCRIPT_LOG_FILE="$LOGS_FOLDER/$GAMESERVERID-backup.log";
#
# Display start of stuff ...
#
source $SCRIPTS_FOLDER/include/include-outputbegin.inc;
#
# Process/validate parameter GAMESERVERID ...
# (or similar backup configuration named similarly)
#
source $SCRIPTS_FOLDER/include/include-gameserverid.inc;
#
# Define some variables ...
#
WORKING_DIRECTORY="$SERVERS_INSTALL_FOLDER";
INCLUDE_FILE="$BACKUP_CONFIGS_FOLDER/$GAMESERVERID-include.txt";
EXCLUDE_FILE="$BACKUP_CONFIGS_FOLDER/$GAMESERVERID-exclude.txt";
OUTPUT_FILE="$BACKUP_FOLDER/$GAMESERVERID-backup.zip";
BACKUP_COMMAND="nice -n 19 7za a -tzip -mmt=off -snl -w$TEMP_FOLDER $OUTPUT_FILE @$INCLUDE_FILE -xr@$EXCLUDE_FILE";
#
# Dispaly what server or backu config is being worked-on ..
#
echo "Game-server (or backup config) to backup: $SERVERDESC [ID=$GAMESERVERID]";
echo "Game-server (or backup config) to backup: $SERVERDESC [ID=$GAMESERVERID]" >> "$SCRIPT_LOG_FILE";
#
# Validate some stuff ...
#
# Validate that required backup "include" file exists ...
#
if [ ! -f $INCLUDE_FILE ]; then
MESSAGE="${ANSI_REDLT}$(figlet "Error:")${ANSI_OFF}\n";
MESSAGE+="${ANSI_WHITE}Required include-list file NOT found at: ${ANSI_REDLT}$INCLUDE_FILE${ANSI_OFF}";
echo -e "$MESSAGE";
if [[ $SCRIPT_LOG_FILE ]]; then
echo -e "$MESSAGE" | ansi2txt >> "$SCRIPT_LOG_FILE";
fi;
#
# Display end of stuff ...
#
source $SCRIPTS_FOLDER/include/include-outputend.inc;
exit 1;
fi;
#
# Validate that required backup "exclude" file exists ...
#
if [ ! -f $EXCLUDE_FILE ]; then
MESSAGE="${ANSI_REDLT}$(figlet "Error:")${ANSI_OFF}\n";
MESSAGE+="${ANSI_WHITE}Required exclude-list file NOT found at: ${ANSI_REDLT}$EXCLUDE_FILE${ANSI_OFF}";
echo -e "$MESSAGE";
if [[ $SCRIPT_LOG_FILE ]]; then
echo -e "$MESSAGE" | ansi2txt >> "$SCRIPT_LOG_FILE";
fi;
#
# Display end of stuff ...
#
source $SCRIPTS_FOLDER/include/include-outputend.inc;
exit 1;
fi;
#
# If in verbose mode, display and log some extra stuff ...
#
if [ "$SCRIPTS_VERBOSE" == true ]; then
echo "Details for this backup process ... ";
echo "Tempory folder (for zipping process): $TEMP_FOLDER";
echo "Include File: $INCLUDE_FILE";
echo "Exclude File: $EXCLUDE_FILE";
echo "Output File: $OUTPUT_FILE";
echo "Backup Command:";
echo "$BACKUP_COMMAND";
fi;
#
# Display and log any existing backups ...
#
echo "Listing any previous backups ...";
echo "Listing any previous backups ..." >> "$SCRIPT_LOG_FILE";
ls -golh $OUTPUT_FILE 2>/dev/null;
ls -golh $OUTPUT_FILE 2>/dev/null >> "$SCRIPT_LOG_FILE";
#
# Delete any previous backup ...
#
echo "Deleting any previous backup ...";
echo "Deleting any previous backup ..." >> "$SCRIPT_LOG_FILE";
rm -f $OUTPUT_FILE 2>/dev/null;
#
# Change to the working directory ...
#
cd $WORKING_DIRECTORY 2>/dev/null;
#
# Create the new backup ...
#
echo "Creating a new backup ...";
echo "Creating a new backup ..." >> "$SCRIPT_LOG_FILE";
echo "Backup command being used:";
echo "Backup command being used:" >> "$SCRIPT_LOG_FILE";
echo "$BACKUP_COMMAND";
echo "$BACKUP_COMMAND" >> "$SCRIPT_LOG_FILE";
$BACKUP_COMMAND >> "$SCRIPT_LOG_FILE";
#
# List the newly created backup file ...
#
echo " ... should be done. Listing backups ... ";
echo " ... should be done. Listing backups ... " >> "$SCRIPT_LOG_FILE";
ls -golh $OUTPUT_FILE 2>/dev/null;
ls -golh $OUTPUT_FILE 2>/dev/null >> "$SCRIPT_LOG_FILE";
#
# Display end of stuff ...
#
source $SCRIPTS_FOLDER/include/include-outputend.inc;
#
# Use 'shift' to move to next parameter passed ...
#
shift;
echo "";
echo "" >> "$SCRIPT_LOG_FILE";
done;
#
# ... thats all folks!
#