mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2024-11-23 16:51:03 +01:00
Compare commits
No commits in common. "8bc2b068ff7723d94e81286ec312b774d0a65497" and "b7dcb17fd50843a51ef6cfeaf0310f22b2688f9a" have entirely different histories.
8bc2b068ff
...
b7dcb17fd5
@ -217,10 +217,7 @@ def is_image_ignored(container):
|
||||
return False
|
||||
|
||||
def backup_with_containers_paused(volume_name, volume_dir, containers, shutdown):
|
||||
if containers:
|
||||
stop_containers(containers)
|
||||
else:
|
||||
print(f"{volume_name} has no containers to stop. Skipped.")
|
||||
stop_containers(containers)
|
||||
backup_volume(volume_name, volume_dir)
|
||||
|
||||
# Just restart containers if shutdown is false
|
||||
@ -284,6 +281,9 @@ def main():
|
||||
for volume_name in volume_names:
|
||||
print(f'Start backup routine for volume: {volume_name}')
|
||||
containers = execute_shell_command(f"docker ps --filter volume=\"{volume_name}\" --format '{{{{.Names}}}}'")
|
||||
if not containers:
|
||||
print('Skipped due to no running containers using this volume.')
|
||||
continue
|
||||
if args.everything:
|
||||
backup_everything(volume_name, containers, args.shutdown)
|
||||
else:
|
||||
|
@ -24,32 +24,19 @@ backup_sql="/$backup_folder/sql/$database_name.backup.sql"
|
||||
|
||||
# DATABASE RECOVERY
|
||||
|
||||
if [ ! -z "$database_type" ]; then
|
||||
if [ "$database_type" = "postgres" ]; then
|
||||
if [ -n "$database_container" ] && [ -n "$database_password" ] && [ -n "$database_name" ]; then
|
||||
echo "Recover PostgreSQL dump"
|
||||
export PGPASSWORD="$database_password"
|
||||
cat "$backup_sql" | docker exec -i "$database_container" psql -v ON_ERROR_STOP=1 -U "$database_user" -d "$database_name"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "ERROR: Failed to recover PostgreSQL dump"
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
elif [ "$database_type" = "mariadb" ]; then
|
||||
if [ -n "$database_container" ] && [ -n "$database_password" ] && [ -n "$database_name" ]; then
|
||||
echo "recover mysql dump"
|
||||
cat "$backup_sql" | docker exec -i "$database_container" mariadb -u "$database_user" --password="$database_password" "$database_name"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "ERROR: Failed to recover mysql dump"
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
if [ -f "$backup_sql" ]; then
|
||||
if [ -n "$database_container" ] && [ -n "$database_password" ] && [ -n "$database_name" ]; then
|
||||
echo "recover mysql dump"
|
||||
cat "$backup_sql" | docker exec -i "$database_container" mariadb -u "$database_user" --password="$database_password" "$database_name"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "ERROR: Failed to recover mysql dump"
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
echo "A database backup exists, but a parameter is missing."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# FILE RECOVERY
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user