feat: add backup and restore scripts
This commit is contained in:
parent
c408a9fe8f
commit
31ae1e0d8f
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
# List of volume names
|
||||
volumes=("selfhosted-owncloud_certs" "selfhosted-owncloud_ocis-config" "selfhosted-owncloud_ocis-data" "selfhosted-owncloud_wopi-recovery")
|
||||
|
||||
# Destination directory for backup
|
||||
backup_dir=$(pwd)
|
||||
|
||||
# Loop through the volumes and create backups
|
||||
for volume in "${volumes[@]}"; do
|
||||
echo "Backing up volume: $volume"
|
||||
docker run --rm -v "$volume":/volume -v "$backup_dir":/backup alpine:latest tar -czvf "/backup/$volume-backup.tar.gz" -C /volume .
|
||||
echo "Backup of volume $volume completed."
|
||||
done
|
||||
|
||||
echo "All backups completed."
|
|
@ -0,0 +1,39 @@
|
|||
#!/bin/bash
|
||||
|
||||
# List of volume names (corresponding to the backup files)
|
||||
volumes=("selfhosted-owncloud_certs" "selfhosted-owncloud_ocis-config" "selfhosted-owncloud_ocis-data" "selfhosted-owncloud_wopi-recovery")
|
||||
|
||||
# Directory where the backup files are located on the new machine
|
||||
backup_dir="/var/www/owncloud"
|
||||
|
||||
# Loop through the volumes and restore backups
|
||||
for volume in "${volumes[@]}"; do
|
||||
backup_file="${volume}-backup.tar.gz"
|
||||
|
||||
# Check if the backup file exists
|
||||
if [ -f "$backup_dir/$backup_file" ]; then
|
||||
echo "Restoring backup for volume: $volume"
|
||||
|
||||
# Use docker inspect to get the host directory path for the volume
|
||||
host_dir=$(docker volume inspect "$volume" --format '{{ .Mountpoint }}')
|
||||
echo $host_dir
|
||||
chmod -R 755 $host_dir
|
||||
|
||||
if [ -n "$host_dir" ]; then
|
||||
# Create the volume if it doesn't exist
|
||||
docker volume create "$volume"
|
||||
|
||||
# Extract the backup file to the volume's host directory
|
||||
# docker run --rm -v "$volume":/volume -v "$backup_dir":/backup alpine:latest tar -xzvf "/backup/$backup_file" -C "$host_dir"
|
||||
tar -xzvf "$backup_dir/$backup_file" -C "$host_dir"
|
||||
|
||||
echo "Backup for volume $volume restored."
|
||||
else
|
||||
echo "Failed to determine host directory for volume $volume. Skipping."
|
||||
fi
|
||||
else
|
||||
echo "Backup file for volume $volume not found in $backup_dir. Skipping."
|
||||
fi
|
||||
done
|
||||
|
||||
echo "All backups restored."
|
Loading…
Reference in New Issue