mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2024-10-31 23:33:11 +01:00
implemented file backup of databases
This commit is contained in:
parent
ff4e192a7b
commit
16e1a76eef
@ -86,32 +86,31 @@ for volume_name in volume_names:
|
|||||||
database_entry = databases_entries.iloc[0]
|
database_entry = databases_entries.iloc[0]
|
||||||
database_backup_command = "docker exec " + container + " /usr/bin/mysqldump -u " + database_entry["username"] + " -p" + database_entry["password"] + " " + database_entry["database"] + " > " + mysqldump_destination_file
|
database_backup_command = "docker exec " + container + " /usr/bin/mysqldump -u " + database_entry["username"] + " -p" + database_entry["password"] + " " + database_entry["database"] + " > " + mysqldump_destination_file
|
||||||
print_bash(database_backup_command)
|
print_bash(database_backup_command)
|
||||||
else:
|
print("Backup files...")
|
||||||
print("Backup files...")
|
files_rsync_destination_path = volume_destination_dir + "/files"
|
||||||
files_rsync_destination_path = volume_destination_dir + "/files"
|
pathlib.Path(files_rsync_destination_path).mkdir(parents=True, exist_ok=True)
|
||||||
pathlib.Path(files_rsync_destination_path).mkdir(parents=True, exist_ok=True)
|
versions = os.listdir(versions_dir)
|
||||||
versions = os.listdir(versions_dir)
|
versions.sort(reverse=True)
|
||||||
versions.sort(reverse=True)
|
if len(versions) > 1:
|
||||||
if len(versions) > 1:
|
last_version = versions[1]
|
||||||
last_version = versions[1]
|
last_version_files_dir = versions_dir + last_version + "/" + volume_name + "/files"
|
||||||
last_version_files_dir = versions_dir + last_version + "/" + volume_name + "/files"
|
if os.path.isdir(last_version_files_dir):
|
||||||
if os.path.isdir(last_version_files_dir):
|
link_dest_parameter="--link-dest='" + last_version_files_dir + "' "
|
||||||
link_dest_parameter="--link-dest='" + last_version_files_dir + "' "
|
|
||||||
else:
|
|
||||||
print("No previous version exists in path "+ last_version_files_dir + ".")
|
|
||||||
link_dest_parameter=""
|
|
||||||
else:
|
else:
|
||||||
print("No previous version exists in path "+ last_version_files_dir + ".")
|
print("No previous version exists in path "+ last_version_files_dir + ".")
|
||||||
link_dest_parameter=""
|
link_dest_parameter=""
|
||||||
source_dir = "/var/lib/docker/volumes/" + volume_name + "/_data/"
|
else:
|
||||||
rsync_command = "rsync -abP --delete --delete-excluded " + link_dest_parameter + source_dir + " " + files_rsync_destination_path
|
print("No previous version exists in path "+ last_version_files_dir + ".")
|
||||||
print_bash(rsync_command)
|
link_dest_parameter=""
|
||||||
print("stop containers...")
|
source_dir = "/var/lib/docker/volumes/" + volume_name + "/_data/"
|
||||||
print("Backup data after container is stopped...")
|
rsync_command = "rsync -abP --delete --delete-excluded " + link_dest_parameter + source_dir + " " + files_rsync_destination_path
|
||||||
print_bash("docker stop " + list_to_string(containers))
|
print_bash(rsync_command)
|
||||||
print_bash(rsync_command)
|
print("stop containers...")
|
||||||
print("start containers...")
|
print("Backup data after container is stopped...")
|
||||||
print_bash("docker start " + list_to_string(containers))
|
print_bash("docker stop " + list_to_string(containers))
|
||||||
|
print_bash(rsync_command)
|
||||||
|
print("start containers...")
|
||||||
|
print_bash("docker start " + list_to_string(containers))
|
||||||
print("end backup routine for volume:" + volume_name)
|
print("end backup routine for volume:" + volume_name)
|
||||||
print('finished volume backups.')
|
print('finished volume backups.')
|
||||||
print('restart docker service...')
|
print('restart docker service...')
|
||||||
|
Loading…
Reference in New Issue
Block a user