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. "e9588b0e31a11f9515048590e1bbb22f04048b1f" and "8bc2b068ff7723d94e81286ec312b774d0a65497" have entirely different histories.
e9588b0e31
...
8bc2b068ff
@ -150,7 +150,6 @@ def getFileRsyncDestinationPath(volume_dir):
|
|||||||
return f"{path}/"
|
return f"{path}/"
|
||||||
|
|
||||||
def backup_volume(volume_name, volume_dir):
|
def backup_volume(volume_name, volume_dir):
|
||||||
try:
|
|
||||||
"""Backup files of a volume with incremental backups."""
|
"""Backup files of a volume with incremental backups."""
|
||||||
print(f"Starting backup routine for volume: {volume_name}")
|
print(f"Starting backup routine for volume: {volume_name}")
|
||||||
files_rsync_destination_path = getFileRsyncDestinationPath(volume_dir)
|
files_rsync_destination_path = getFileRsyncDestinationPath(volume_dir)
|
||||||
@ -162,11 +161,6 @@ def backup_volume(volume_name, volume_dir):
|
|||||||
source_dir = getStoragePath(volume_name)
|
source_dir = getStoragePath(volume_name)
|
||||||
rsync_command = f"rsync -abP --delete --delete-excluded {link_dest_option} {source_dir} {files_rsync_destination_path}"
|
rsync_command = f"rsync -abP --delete --delete-excluded {link_dest_option} {source_dir} {files_rsync_destination_path}"
|
||||||
execute_shell_command(rsync_command)
|
execute_shell_command(rsync_command)
|
||||||
except BackupException as e:
|
|
||||||
if "file has vanished" in e.args[0]:
|
|
||||||
print("Warning: Some files vanished before transfer. Continuing.")
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
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):
|
||||||
@ -177,14 +171,17 @@ def has_image(container,image):
|
|||||||
image_info = get_image_info(container)
|
image_info = get_image_info(container)
|
||||||
return image in image_info[0]
|
return image in image_info[0]
|
||||||
|
|
||||||
def change_containers_status(containers,status):
|
def stop_containers(containers):
|
||||||
"""Stop a list of containers."""
|
"""Stop a list of containers."""
|
||||||
if containers:
|
|
||||||
container_list = ' '.join(containers)
|
container_list = ' '.join(containers)
|
||||||
print(f"{status} containers {container_list}...")
|
print(f"Stopping containers {container_list}...")
|
||||||
execute_shell_command(f"docker {status} {container_list}")
|
execute_shell_command(f"docker stop {container_list}")
|
||||||
else:
|
|
||||||
print(f"No containers to {status}.")
|
def start_containers(containers):
|
||||||
|
"""Start a list of containers."""
|
||||||
|
container_list = ' '.join(containers)
|
||||||
|
print(f"Start containers {container_list}...")
|
||||||
|
execute_shell_command(f"docker start {container_list}")
|
||||||
|
|
||||||
def get_container_with_image(containers,image):
|
def get_container_with_image(containers,image):
|
||||||
for container in containers:
|
for container in containers:
|
||||||
@ -220,12 +217,15 @@ def is_image_ignored(container):
|
|||||||
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, shutdown):
|
||||||
change_containers_status(containers,'stop')
|
if containers:
|
||||||
|
stop_containers(containers)
|
||||||
|
else:
|
||||||
|
print(f"{volume_name} has no containers to stop. Skipped.")
|
||||||
backup_volume(volume_name, volume_dir)
|
backup_volume(volume_name, volume_dir)
|
||||||
|
|
||||||
# Just restart containers if shutdown is false
|
# Just restart containers if shutdown is false
|
||||||
if not shutdown:
|
if not shutdown:
|
||||||
change_containers_status(containers,'start')
|
start_containers(containers)
|
||||||
|
|
||||||
def backup_mariadb_or_postgres(container, volume_dir):
|
def backup_mariadb_or_postgres(container, volume_dir):
|
||||||
'''Performs database image specific backup procedures'''
|
'''Performs database image specific backup procedures'''
|
||||||
|
Loading…
Reference in New Issue
Block a user