Added backup function

This commit is contained in:
Price Hiller 2021-12-24 23:07:00 -06:00
parent 195e28421e
commit 2eea6f5521

View File

@ -141,6 +141,7 @@ done" C-m
kill_server() { kill_server() {
local prefix local prefix
local tmux_response
local server_id local server_id
server_id="" server_id=""
@ -281,14 +282,10 @@ update() {
# Kill the server to ensure a smooth update # Kill the server to ensure a smooth update
kill_server -s "${server_id}" >/dev/null 2>&1 kill_server -s "${server_id}" >/dev/null 2>&1
local backup_dir
local backup_full_path
local server_directory local server_directory
local server_name local server_name
server_name="Server-${server_id}" server_name="Server-${server_id}"
server_directory="${BASE_DIR}/${server_name}" server_directory="${BASE_DIR}/${server_name}"
backup_dir="${HOME}/Server-Backups/${server_name}"
backup_full_path="${backup_dir}/$(date +%s).tar.gz"
backup -s "${server_id}" backup -s "${server_id}"
log "info" "Updating server $(important "${server_name}") located at $(important "${server_directory}")..." log "info" "Updating server $(important "${server_name}") located at $(important "${server_directory}")..."
steamcmd +force_install_dir "${server_directory}" +login anonymous +app_update 294420 validate +quit steamcmd +force_install_dir "${server_directory}" +login anonymous +app_update 294420 validate +quit
@ -351,7 +348,6 @@ backup() {
log "info" "Backing up server $(important "${server_name}") to $(important "${backup_full_path}"), this may take a while" log "info" "Backing up server $(important "${server_name}") to $(important "${backup_full_path}"), this may take a while"
mkdir -p "${backup_dir}" mkdir -p "${backup_dir}"
set -x
tar cf - "${server_directory}" -P | pv -s "$(du -sb "${server_directory}" | awk '{print $1}')" | \ tar cf - "${server_directory}" -P | pv -s "$(du -sb "${server_directory}" | awk '{print $1}')" | \
gzip > "${backup_full_path}" gzip > "${backup_full_path}"
tar -czf "${server_directory}" "${backup_dir}"/ tar -czf "${server_directory}" "${backup_dir}"/
@ -400,29 +396,26 @@ list_servers() {
log "error" "An option must be passed for list, check list -h" && log "error" "An option must be passed for list, check list -h" &&
return 1 return 1
case "${picked_option}" in if (( picked_option == 0 )); then
1) log "debug" "Listing running servers"
log "debug" "Listing running servers" local tmux_sessions
local tmux_sessions tmux_sessions="$(tmux list-sessions)" >/dev/null 2>&1
tmux_sessions="$(tmux list-sessions)" >/dev/null 2>&1 if [[ ! "${?}" -eq "0" ]]; then
if [[ ! "${?}" -eq "0" ]]; then important "No servers currently running."
important "No servers currently running." fi
while read -r; do
if [[ "${REPLY}" = *"-Server-"* ]]; then
local running_server
running_server="$(echo "${REPLY}" | cut -d ":" -f1)"
important "${running_server}"
fi fi
while read -r; do done <<< "${tmux_sessions}"
if [[ "${REPLY}" = *"-Server-"* ]]; then elif (( picked_option == 1 )); then
local running_server log "debug" "Listing installed servers"
running_server="$(echo "${REPLY}" | cut -d ":" -f1)" while read -r; do
important "${running_server}" important "${BASE_DIR}/${REPLY}"
fi done <<< "$(find "${BASE_DIR}" -name "startserver.sh" | cut -d "/" -f5)"
done <<< "${tmux_sessions}" fi
;;
2)
log "debug" "Listing installed servers"
while read -r; do
important "${BASE_DIR}/${REPLY}"
done <<< "$(find "${BASE_DIR}" -name "startserver.sh" | cut -d "/" -f5)"
;;
esac
} }
usage() { usage() {