mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2024-11-25 09:41:03 +01:00
Compare commits
No commits in common. "7702b17a9d05ba7d2bd86cfedfabaaea1052514d" and "bf9986f2829600d09a6baee6d32a8df883b47cbc" have entirely different histories.
7702b17a9d
...
bf9986f282
@ -142,7 +142,7 @@ def get_last_backup_dir(volume_name, current_backup_dir):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def getStoragePath(volume_name):
|
def getStoragePath(volume_name):
|
||||||
return execute_shell_command(f"docker volume inspect --format '{{{{ .Mountpoint }}}}' {volume_name}")
|
return execute_shell_command(f"docker volume inspect {volume_name} | jq -r '.[0].Mountpoint'")
|
||||||
|
|
||||||
def backup_volume(volume_name, volume_dir):
|
def backup_volume(volume_name, volume_dir):
|
||||||
"""Backup files of a volume with incremental backups."""
|
"""Backup files of a volume with incremental backups."""
|
||||||
@ -159,7 +159,7 @@ def backup_volume(volume_name, volume_dir):
|
|||||||
print(f"Backup routine for volume: {volume_name} completed.")
|
print(f"Backup routine for volume: {volume_name} completed.")
|
||||||
|
|
||||||
def get_image_info(container):
|
def get_image_info(container):
|
||||||
return execute_shell_command(f"docker inspect --format '{{{{.Config.Image}}}}' {container}")
|
return execute_shell_command(f"docker inspect {container} | jq -r '.[].Config.Image'")
|
||||||
|
|
||||||
def has_image(container,image):
|
def has_image(container,image):
|
||||||
"""Check if the container is using the image"""
|
"""Check if the container is using the image"""
|
||||||
@ -211,12 +211,9 @@ def is_image_ignored(container):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def backup_with_containers_paused(volume_name, volume_dir, containers, shutdown):
|
def backup_with_containers_paused(volume_name, volume_dir, containers):
|
||||||
stop_containers(containers)
|
stop_containers(containers)
|
||||||
backup_volume(volume_name, volume_dir)
|
backup_volume(volume_name, volume_dir)
|
||||||
|
|
||||||
# Just restart containers if shutdown is false
|
|
||||||
if not shutdown:
|
|
||||||
start_containers(containers)
|
start_containers(containers)
|
||||||
|
|
||||||
def backup_mariadb_or_postgres(container, volume_dir):
|
def backup_mariadb_or_postgres(container, volume_dir):
|
||||||
@ -227,7 +224,8 @@ def backup_mariadb_or_postgres(container, volume_dir):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def default_backup_routine_for_volume(volume_name, containers, shutdown):
|
|
||||||
|
def default_backup_routine_for_volume(volume_name, containers):
|
||||||
"""Perform backup routine for a given volume."""
|
"""Perform backup routine for a given volume."""
|
||||||
volume_dir=""
|
volume_dir=""
|
||||||
for container in containers:
|
for container in containers:
|
||||||
@ -248,9 +246,9 @@ def default_backup_routine_for_volume(volume_name, containers, shutdown):
|
|||||||
if volume_dir:
|
if volume_dir:
|
||||||
backup_volume(volume_name, volume_dir)
|
backup_volume(volume_name, volume_dir)
|
||||||
if is_container_stop_required(containers):
|
if is_container_stop_required(containers):
|
||||||
backup_with_containers_paused(volume_name, volume_dir, containers, shutdown)
|
backup_with_containers_paused(volume_name, volume_dir, containers)
|
||||||
|
|
||||||
def backup_everything(volume_name, containers, shutdown):
|
def backup_everything(volume_name, containers):
|
||||||
"""Perform file backup routine for a given volume."""
|
"""Perform file backup routine for a given volume."""
|
||||||
volume_dir=create_volume_directory(volume_name)
|
volume_dir=create_volume_directory(volume_name)
|
||||||
|
|
||||||
@ -260,14 +258,12 @@ def backup_everything(volume_name, containers, shutdown):
|
|||||||
|
|
||||||
# Execute file backups
|
# Execute file backups
|
||||||
backup_volume(volume_name, volume_dir)
|
backup_volume(volume_name, volume_dir)
|
||||||
backup_with_containers_paused(volume_name, volume_dir, containers, shutdown)
|
backup_with_containers_paused(volume_name, volume_dir, containers)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='Backup Docker volumes.')
|
parser = argparse.ArgumentParser(description='Backup Docker volumes.')
|
||||||
parser.add_argument('--everything', action='store_true',
|
parser.add_argument('--everything', action='store_true',
|
||||||
help='Force file backup for all volumes and additional execute database dumps')
|
help='Force file backup for all volumes and additional execute database dumps')
|
||||||
parser.add_argument('--shutdown', action='store_true',
|
|
||||||
help='Doesn\'t restart containers after backup')
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
print('Start volume backups...')
|
print('Start volume backups...')
|
||||||
@ -280,9 +276,9 @@ def main():
|
|||||||
print('Skipped due to no running containers using this volume.')
|
print('Skipped due to no running containers using this volume.')
|
||||||
continue
|
continue
|
||||||
if args.everything:
|
if args.everything:
|
||||||
backup_everything(volume_name, containers, args.shutdown)
|
backup_everything(volume_name, containers)
|
||||||
else:
|
else:
|
||||||
default_backup_routine_for_volume(volume_name, containers, args.shutdown)
|
default_backup_routine_for_volume(volume_name, containers)
|
||||||
|
|
||||||
print('Finished volume backups.')
|
print('Finished volume backups.')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user