backup functionality
This commit is contained in:
parent
1098abe354
commit
3e64261986
2 changed files with 42 additions and 2 deletions
|
@ -5,7 +5,41 @@ function backup_help() {
|
||||||
cat<<EOF
|
cat<<EOF
|
||||||
commands:
|
commands:
|
||||||
create [servername]
|
create [servername]
|
||||||
destroy [backup-name]
|
destroy [servername] [backup-name]
|
||||||
list
|
list [servername]
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function backup_create() {
|
||||||
|
checkBackupDir "${1}"
|
||||||
|
|
||||||
|
local backupdir="$(getValueByKey 'PODMAN_DIRECTORY')/${1}/backup"
|
||||||
|
local datadir="$(getValueByKey 'PODMAN_DIRECTORY')/${1}/data"
|
||||||
|
|
||||||
|
tar -czf "$backupdir/${1}-$(date '+%d-%m-%Y_%T').tar.gz" \
|
||||||
|
-C "$datadir" logs/ \
|
||||||
|
-C "$datadir" plugins/ \
|
||||||
|
-C "$datadir" crash-reports \
|
||||||
|
-C "$datadir" world/ \
|
||||||
|
-C "$datadir" world_nether/ \
|
||||||
|
-C "$datadir" world_the_end/
|
||||||
|
}
|
||||||
|
|
||||||
|
function backup_destroy() {
|
||||||
|
local backupdir="$(getValueByKey 'PODMAN_DIRECTORY')/${1}/backup"
|
||||||
|
if [[ ! -f "${backupdir}/${2}.tar.gz" ]]; then
|
||||||
|
log e "Backup ${2%} does not exist! Check again using '$(basename 0) backup list'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
rm "${backupdir}/${2}.tar.gz"
|
||||||
|
}
|
||||||
|
|
||||||
|
function backup_list() {
|
||||||
|
local backupdir="$(getValueByKey 'PODMAN_DIRECTORY')/${1}/backup"
|
||||||
|
local found_backups="$(find "$backupdir" -type f -print)"
|
||||||
|
|
||||||
|
log i "Found ${#found_backups[@]} backups:"
|
||||||
|
for backup in "${found_backups[@]}"; do
|
||||||
|
basename "${backup%%.*}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
|
@ -109,3 +109,9 @@ function populateConfig() {
|
||||||
|
|
||||||
jq "(.type=\"${runnertype}\")|(.build=${build})|(.software=\"${software}\")|(.release=\"${release}\")|(.version=\"${version}\")|(.podman_network=\"${network_name}\")" ${TEMPLATEDIR}/config.json > "${config}"
|
jq "(.type=\"${runnertype}\")|(.build=${build})|(.software=\"${software}\")|(.release=\"${release}\")|(.version=\"${version}\")|(.podman_network=\"${network_name}\")" ${TEMPLATEDIR}/config.json > "${config}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkBackupDir() {
|
||||||
|
if [[ ! -d "$(getValueByKey 'PODMAN_DIRECTORY')/${1}/backup" ]]; then
|
||||||
|
mkdir -p "$(getValueByKey 'PODMAN_DIRECTORY')/${1}/backup"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue