mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2024-11-24 17:21:03 +01:00
implemented exception handling for rsync 24
This commit is contained in:
parent
c4107d91b0
commit
b83e481d01
@ -64,3 +64,4 @@ This project is licensed under the GNU Affero General Public License v3.0. The f
|
||||
- https://zwischenzugs.com/2016/08/29/bash-to-python-converter/
|
||||
- https://en.wikipedia.org/wiki/Incremental_backup#Incremental
|
||||
- https://unix.stackexchange.com/questions/567837/linux-backup-utility-for-incremental-backups
|
||||
- https://chat.openai.com/share/6d10f143-3f7c-4feb-8ae9-5644c3433a65
|
@ -8,20 +8,29 @@ import pathlib
|
||||
import pandas
|
||||
from datetime import datetime
|
||||
|
||||
class RsyncCode24Exception(Exception):
|
||||
"""Exception for rsync error code 24."""
|
||||
"""rsync warning: some files vanished before they could be transferred"""
|
||||
pass
|
||||
|
||||
def bash(command):
|
||||
print(command)
|
||||
process = subprocess.Popen([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||
out, err = process.communicate()
|
||||
stdout = out.splitlines()
|
||||
output = []
|
||||
for line in stdout:
|
||||
output.append(line.decode("utf-8"))
|
||||
if process.wait() > bool(0):
|
||||
print(command, out, err)
|
||||
raise Exception("Exitcode is greater then 0")
|
||||
return output
|
||||
stderr = err.decode("utf-8")
|
||||
output = [line.decode("utf-8") for line in stdout]
|
||||
|
||||
exitcode = process.wait()
|
||||
if exitcode != 0:
|
||||
print(f"Error in command: {command}\nOutput: {out}\nError: {err}\nExit code: {exitcode}")
|
||||
|
||||
if "rsync" in command and exitcode == 24:
|
||||
raise RsyncCode24Exception(f"rsync error code 24 encountered: {stderr}")
|
||||
|
||||
raise Exception("Exit code is greater than 0")
|
||||
|
||||
return output
|
||||
|
||||
def print_bash(command):
|
||||
output = bash(command)
|
||||
@ -95,7 +104,10 @@ for volume_name in volume_names:
|
||||
link_dest_parameter=""
|
||||
source_dir = "/var/lib/docker/volumes/" + volume_name + "/_data/"
|
||||
rsync_command = "rsync -abP --delete --delete-excluded " + link_dest_parameter + source_dir + " " + files_rsync_destination_path
|
||||
try:
|
||||
print_bash(rsync_command)
|
||||
except RsyncCode24Exception:
|
||||
print("Ignoring rsync error code 24, proceeding with the next command.")
|
||||
print("stop containers...")
|
||||
print("Backup data after container is stopped...")
|
||||
print_bash("docker stop " + list_to_string(containers))
|
||||
|
Loading…
Reference in New Issue
Block a user