Skip to content

Commit

Permalink
fix restore.sh spacing -> 4x
Browse files Browse the repository at this point in the history
  • Loading branch information
seoseonyu authored Jan 31, 2024
1 parent 2e0186e commit f81e972
Showing 1 changed file with 71 additions and 70 deletions.
141 changes: 71 additions & 70 deletions scripts/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ BACKUP_DIRECTORY_PATH="/palworld/backups"
# Resotre path
RESTORE_PATH="/palworld/Pal"

# shellcheck disable=SC2317
term_error_handler() {
echo "An error occurred during server shutdown."
exit 1
}

# shellcheck disable=SC2317
restore_error_handler() {
printf "\033[0;31mAn error occurred during restore.\033[0m\n"
if [ -d "./tmp_save/Saved" ]; then
read -rp "I have a backup before recovery can proceed. Do you want to recovery it? (y/n): " RUN_ANSWER
if [[ $RUN_ANSWER == "y" ]] || [[ $RUN_ANSWER == "Y" ]]; then
rm -rf "$RESTORE_PATH/Saved"
mv "./tmp_save/Saved" "$RESTORE_PATH"
printf "\e[0;32mRecovery complete.\e[0m\n"
fi
read -rp "I have a backup before recovery can proceed. Do you want to recovery it? (y/n): " RUN_ANSWER
if [[ $RUN_ANSWER == "y" ]] || [[ $RUN_ANSWER == "Y" ]]; then
rm -rf "$RESTORE_PATH/Saved"
mv "./tmp_save/Saved" "$RESTORE_PATH"
printf "\e[0;32mRecovery complete.\e[0m\n"
fi
fi

rm -rf "./tmp"
Expand All @@ -29,8 +30,8 @@ restore_error_handler() {
}

if [ "${RCON_ENABLED}" != true ]; then
echo "RCON is not enabled. Please enable RCON to use this feature."
exit 1
echo "RCON is not enabled. Please enable RCON to use this feature."
exit 1
fi

# Show up backup list
Expand All @@ -45,70 +46,70 @@ select BACKUP_FILE in "$BACKUP_DIRECTORY_PATH"/*; do
done

if [ -f "$BACKUP_FILE" ]; then
echo "Do you want to continue with the command?"
read -rp "When you run it, the server will be stopped and the recovery will proceed. (y/n): " RUN_ANSWER
if [[ $RUN_ANSWER == "y" ]] || [[ $RUN_ANSWER == "Y" ]]; then
printf "\e[0;32m*****STARTING PROCESS*****\e[0m\n"
# Shutdown server
trap 'term_error_handler' ERR

if [ "${RCON_ENABLED}" = true ]; then
printf "\e[0;32m*****SHUTDOWN SERVER*****\e[0m\n"
rcon-cli -c /home/steam/server/rcon.yaml save
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
echo "Do you want to continue with the command?"
read -rp "When you run it, the server will be stopped and the recovery will proceed. (y/n): " RUN_ANSWER
if [[ $RUN_ANSWER == "y" ]] || [[ $RUN_ANSWER == "Y" ]]; then
printf "\e[0;32m*****STARTING PROCESS*****\e[0m\n"
# Shutdown server
trap 'term_error_handler' ERR

if [ "${RCON_ENABLED}" = true ]; then
printf "\e[0;32m*****SHUTDOWN SERVER*****\e[0m\n"
rcon-cli -c /home/steam/server/rcon.yaml save
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
else
echo "RCON is not enabled. Please enable RCON to use this feature. Unable to restore backup."
exit 1
fi
printf "\e[0;32mShutdown complete.\e[0m\n"

trap - ERR

trap 'restore_error_handler' ERR

printf "\e[0;32m*****START RESTORE*****\e[0m\n"

# Recheck the backup file
if [ -f "$BACKUP_FILE" ]; then
# Copy the save file before restore
if [ -d "$RESTORE_PATH/Saved" ]; then
echo "Saves the current state before the restore proceeds."
rm -rf "./tmp_save"
mkdir -p "./tmp_save"
\cp -rf "$RESTORE_PATH/Saved" "./tmp_save/Saved"

while [ ! -d "./tmp_save/Saved" ]; do
sleep 1
done

printf "\e[0;32mSave complete.\e[0m\n"
fi

# Create tmp directory
rm -rf "./tmp"
mkdir -p "./tmp"

# Decompress the backup file in tmp directory
tar -zxvf "$BACKUP_FILE" -C "./tmp"

# Move the backup file to the restore directory
\cp -rf -f "./tmp/Saved/" "$RESTORE_PATH"

# Remove tmp directory
rm -rf "./tmp"
rm -rf "./tmp_save"

printf "\e[0;32mRestore complete!!!! Please restart the Docker container\e[0m\n"

exit 0
else
echo "The selected backup file does not exist."
exit 1
fi
else
echo "RCON is not enabled. Please enable RCON to use this feature. Unable to restore backup."
echo "Abort the recovery."
exit 1
fi
printf "\e[0;32mShutdown complete.\e[0m\n"

trap - ERR

trap 'restore_error_handler' ERR

printf "\e[0;32m*****START RESTORE*****\e[0m\n"

# Recheck the backup file
if [ -f "$BACKUP_FILE" ]; then
# Copy the save file before restore
if [ -d "$RESTORE_PATH/Saved" ]; then
echo "Saves the current state before the restore proceeds."
rm -rf "./tmp_save"
mkdir -p "./tmp_save"
\cp -rf "$RESTORE_PATH/Saved" "./tmp_save/Saved"

while [ ! -d "./tmp_save/Saved" ]; do
sleep 1
done

printf "\e[0;32mSave complete.\e[0m\n"
fi

# Create tmp directory
rm -rf "./tmp"
mkdir -p "./tmp"

# Decompress the backup file in tmp directory
tar -zxvf "$BACKUP_FILE" -C "./tmp"

# Move the backup file to the restore directory
\cp -rf -f "./tmp/Saved/" "$RESTORE_PATH"

# Remove tmp directory
rm -rf "./tmp"
rm -rf "./tmp_save"

printf "\e[0;32mRestore complete!!!! Please restart the Docker container\e[0m\n"

exit 0
else
echo "The selected backup file does not exist."
exit 1
fi
else
echo "Abort the recovery."
exit 1
fi
else
echo "The selected backup file does not exist."
exit 1
Expand Down

0 comments on commit f81e972

Please sign in to comment.