diff --git a/docker-backup.sh b/docker-backup.sh index 92ca595..8b3b95b 100644 --- a/docker-backup.sh +++ b/docker-backup.sh @@ -24,7 +24,7 @@ EOF # ================================================== debug=${DEBUG:-} -version=1.0.0 +version=1.0.1 today=$(date +'%F') stackdir="/etc/komodo/stacks" backupdir="/backups" @@ -53,6 +53,24 @@ function startServices() { done } +function backupStacks() { + echo "Backing up stacks..." + local dir="$1/stacks" + mkdir "$dir" + for service in "${services[@]}"; do + cp -r --parents "$service" "$dir" + done +} + +function backupVolumes() { + echo "Backing up volumes..." + local dir="$1/volumes" + mkdir "$dir" + for volume in "${volumes[@]}"; do + cp -r --parents "$volume" "$dir" + done +} + function backup() { echo "Creating backup..." tar -cvzf "/$today.tar.gz" "$1" @@ -78,7 +96,7 @@ function copyIfNotDebug { fi } -function copyVolumes() { +function restoreVolumes() { echo "Copying volumes..." local volumes=($(find "$1/volumes" -maxdepth 1 -mindepth 1 -type d)) for volume in "${volumes[@]}"; do @@ -87,7 +105,7 @@ function copyVolumes() { done } -function copyStacks() { +function restoreStacks() { echo "Copying stacks..." local stacks=($(find "$1/stacks" -maxdepth 1 -mindepth 1 -type d)) for stack in "${stacks[@]}"; do @@ -105,10 +123,10 @@ function run() { mkdir "$temp" # copy stack configuration. - copyStacks "$temp" + backupStacks "$temp" # copy stack configuration. - copyVolumes "$temp" + backupVolumes "$temp" # Create a tar to backup. backup "$temp" @@ -136,8 +154,8 @@ function restore() { tar -xvf "$archive" # copy stacks and volumes to their locations. - copyVolumes "$dir" - copyStacks "$dir" + restoreVolumes "$dir" + restoreStacks "$dir" # cleanup rm -rf "$dir" diff --git a/install.sh b/install.sh index b787339..322fa41 100644 --- a/install.sh +++ b/install.sh @@ -6,11 +6,6 @@ bindir="/usr/local/bin" function downloadScripts() { local script="docker-backup" - local scriptsToRemove=( - "docker-restore" - "docker-restart" - ) - # set the destination of the script. local dest="$bindir/$script" # Remove the file if it exists. @@ -19,10 +14,6 @@ function downloadScripts() { wget "$baseurl/$script.sh" -O "$dest" # make the script executable. chmod +x "$dest" - - for script in "${scriptsToRemove[@]}"; do - [ -f "$script" ] && rm -f "$script" - done } # Remove backup service file if it exists and install the service file.