-
Notifications
You must be signed in to change notification settings - Fork 0
/
game-server-restore.sh
executable file
·153 lines (153 loc) · 4.72 KB
/
game-server-restore.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
#!/bin/bash
#
# ----------------------------------------------------------------------------
# Restore 7-zip backups(s) created by the game-server-backup.sh script
# ============================================================================
# Created: 2024-05-24, by [email protected]
# Last modified: 2024-06-13, by [email protected]
# ----------------------------------------------------------------------------
#
# Purpose:
#
# The game-server name/ID (or other backup config/ID)
# will determine the name of the folder to restore.
# Accepts multiple backupconfigids in the same command-line.
#
# Usage / command-line parameters:
#
# gameserverid
#
# The game-server identifier(s) for the game-server(s) to restore.
#
# Example:
#
# ./game-server-restore.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-restore.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";
INPUT_FILE="$BACKUP_FOLDER/$GAMESERVERID-backup.zip";
RESTORE_FOLDER="$SERVERS_INSTALL_FOLDER/$GAMESERVERID";
RESTORE_COMMAND="nice -n 19 7za x -mmt=off -aoa -o$WORKING_DIRECTORY -w$TEMP_FOLDER $INPUT_FILE"
#
# Dispaly that is being restored ..
#
echo "Game-server (or backup config) to restore: [ID=$GAMESERVERID]";
echo "Game-server (or backup config) to restore: [ID=$GAMESERVERID]" >> "$SCRIPT_LOG_FILE";
#
# If in verbose mode, display and log some extra stuff ...
#
if [ "$SCRIPTS_VERBOSE" == true ]; then
echo "Details for this restore process ... ";
echo "Tempory folder (for zipping process): $TEMP_FOLDER";
echo "Input File: $INPUT_FILE";
echo "Restore Folder: $RESTORE_FOLDER"
echo "Restore Command:";
echo "$RESTORE_COMMAND";
fi;
#
# Display and log any existing backups ...
#
echo "List any matching backups available ...";
echo "List any matching backups available ..." >> "$SCRIPT_LOG_FILE";
ls -golh $INPUT_FILE 2>/dev/null;
ls -golh $INPUT_FILE 2>/dev/null >> "$SCRIPT_LOG_FILE";
#
# Change to the working directory ...
#
cd $WORKING_DIRECTORY 2>/dev/null;
#
# Create the new backup ...
#
echo "Restoring the backup ...";
echo "Restoring the backup ..." >> "$SCRIPT_LOG_FILE";
echo "Restore command being used:";
echo "Restore command being used:" >> "$SCRIPT_LOG_FILE";
echo "$RESTORE_COMMAND";
echo "$RESTORE_COMMAND" >> "$SCRIPT_LOG_FILE";
$RESTORE_COMMAND >> "$SCRIPT_LOG_FILE";
#
# Display (some) of the restore result ...
#
if [ "$SCRIPTS_VERBOSE" == true ]; then
#
# If in verbose mode, display full directory listing ..
#
echo " Listing restored folder ... ";
echo " Listing restored folder ... " >> "$SCRIPT_LOG_FILE";
tree --dirsfirst $RESTORE_FOLDER 2>/dev/null;
tree --dirsfirst $RESTORE_FOLDER 2>/dev/null >> "$SCRIPT_LOG_FILE";
else
#
# If NOT in verbose mode, limit directory listing to 2 levels ...
# (but still send full listing to log file)
#
echo " Listing restored folder (listing limited to 2 levels deep) ... ";
echo " Listing restored folder ... " >> "$SCRIPT_LOG_FILE";
tree --dirsfirst -L 2 $RESTORE_FOLDER 2>/dev/null;
tree --dirsfirst $RESTORE_FOLDER 2>/dev/null >> "$SCRIPT_LOG_FILE";
fi;
#
# 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!
#