feat: Adds restore script.
This commit is contained in:
11
README.md
11
README.md
@@ -50,3 +50,14 @@ sudo systemctl start backup.service
|
||||
1. Add any extra volumes to backup.
|
||||
1. Make script executable `chmod +x docker-backup.sh`
|
||||
1. Manually run the script `sudo ./docker-backup.sh`
|
||||
|
||||
## Restore
|
||||
|
||||
This repository also contains a restore script that can restore the stacks and
|
||||
volumes from a backup (hopefully it's never needed!).
|
||||
|
||||
### Usage
|
||||
|
||||
1. Download the script `wget https://git.housh.dev/homelab/backup/raw/branch/main/docker-restore.sh`
|
||||
1. Make script executable `chmod +x docker-restore.sh`
|
||||
1. Run the script `sudo ./docker-restore.sh /backups/<backup>.tar.gz`
|
||||
|
||||
@@ -30,7 +30,7 @@ function copyStacks() {
|
||||
local dir="$1/stacks"
|
||||
mkdir "$dir"
|
||||
for service in "${services[@]}"; do
|
||||
cp -R "$service" "$dir"
|
||||
cp -r --parents "$service" "$dir"
|
||||
done
|
||||
}
|
||||
|
||||
@@ -39,17 +39,16 @@ function copyVolumes() {
|
||||
local dir="$1/volumes"
|
||||
mkdir "$dir"
|
||||
for volume in "${volumes[@]}"; do
|
||||
cp -R "$volume" "$dir"
|
||||
cp -r --parents "$volume" "$dir"
|
||||
done
|
||||
}
|
||||
|
||||
function backup() {
|
||||
echo "Creating backup..."
|
||||
tar -cvf "/$today.tar" "$1"
|
||||
gzip "/$today.tar"
|
||||
cp -R "/$today.tar.gz" "$backupdir"
|
||||
tar -cvzf "/$today.tar.gz" "$1"
|
||||
cp -r "/$today.tar.gz" "$backupdir"
|
||||
# Cleanup temporary files.
|
||||
rm -rf "$1" "/$today.tar" "/$today.tar.gz"
|
||||
rm -rf "$1" "/$today.tar.gz"
|
||||
}
|
||||
|
||||
function main() {
|
||||
@@ -57,7 +56,7 @@ function main() {
|
||||
stopServices
|
||||
|
||||
# Create a temporary directory.
|
||||
local temp="/tmp/$today"
|
||||
local temp="/$today"
|
||||
mkdir "$temp"
|
||||
|
||||
# copy stack configuration.
|
||||
|
||||
46
docker-restore.sh
Normal file
46
docker-restore.sh
Normal file
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
debug=${DEBUG:-}
|
||||
|
||||
function copyIfNotDebug {
|
||||
if [ -z "$debug" ]; then
|
||||
cp -r "$1" "$2"
|
||||
else
|
||||
echo "$1 -> $2"
|
||||
fi
|
||||
}
|
||||
|
||||
function copyVolumes() {
|
||||
echo "Copying volumes..."
|
||||
local volumes=($(find "$1/volumes" -maxdepth 1 -mindepth 1 -type d))
|
||||
for volume in "${volumes[@]}"; do
|
||||
local dest="${volume#"$1"/volumes*}"
|
||||
copyIfNotDebug "$volume" "$dest"
|
||||
done
|
||||
}
|
||||
|
||||
function copyStacks() {
|
||||
echo "Copying stacks..."
|
||||
local stacks=($(find "$1/stacks" -maxdepth 1 -mindepth 1 -type d))
|
||||
for stack in "${stacks[@]}"; do
|
||||
local dest="${stack#"$1"/stacks*}"
|
||||
copyIfNotDebug "$stack" "$dest"
|
||||
done
|
||||
}
|
||||
|
||||
function main() {
|
||||
local archive="$1"
|
||||
local dir="${archive%*.tar.gz}"
|
||||
|
||||
# unzip the archive.
|
||||
tar -xvf "$archive"
|
||||
|
||||
# copy stacks and volumes to their locations.
|
||||
copyVolumes "$dir"
|
||||
copyStacks "$dir"
|
||||
|
||||
# cleanup
|
||||
rm -rf "$dir"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user