#!/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."