tar backuper cousin to rsync-backup

This commit is contained in:
Q
2023-10-21 22:19:41 +03:00
parent ec1c5f249e
commit 71ce8d182f
2 changed files with 39 additions and 20 deletions

View File

@@ -103,7 +103,9 @@ class RSB:
if os.path.exists(tgt_dir):
raise FileExistsError("Folder {} already exists".format(tgt_dir))
subprocess.call(["cp", "-ldr", "--preserve=xattr", self.current, tgt_dir], shell=False)
subprocess.call(
["cp", "-ldr", "--preserve=xattr", self.current, tgt_dir], shell=False
)
def make_backup(self):
if self.options.no_backup:
@@ -123,7 +125,6 @@ class RSB:
return success
def write_config(self):
conf = json.dumps(vars(self.options))
with open(self.config_file, "wt") as fp:
fp.write(
@@ -164,7 +165,6 @@ rsync-backup \\
def get_opts():
parser = ArgumentParser(
description="Minimal incrementive backup utility using rsync and hard links.",
)

View File

@@ -114,14 +114,24 @@ class TB:
os.makedirs(os.path.join(self.base_folder, self.backup_folder), exist_ok=True)
print("Backing up")
ssh_command = (
[
"ssh",
*shlex.split(self.ssh_args),
]
if self.ssh_args
else []
)
ssh_command = [
"ssh",
*shlex.split(self.ssh_args),
] if self.ssh_args else []
with open(os.path.join(self.base_folder, self.backup_folder,self.tar_file), "wb") as fp:
with open(os.path.join(self.base_folder, self.backup_folder,self.tar_file+".log"), "w") as fp_log:
with open(
os.path.join(self.base_folder, self.backup_folder, self.tar_file), "wb"
) as fp:
with open(
os.path.join(
self.base_folder, self.backup_folder, self.tar_file + ".log"
),
"w",
) as fp_log:
command = [
*ssh_command,
"tar",
@@ -131,29 +141,39 @@ class TB:
print(command)
md5 = hashlib.md5()
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=fp_log)
i=1
i = 1
while True:
chunk = p.stdout.read(1048576)
if len(chunk) == 0:
break
print(f"{i} Mb", end='\r')
i+=1
print(f"{i} Mb", end="\r")
i += 1
md5.update(chunk)
fp.write(chunk)
exitcode = p.wait()
success = exitcode in (0, 2)
print(f"\nWrote {os.path.join(self.base_folder, self.backup_folder,self.tar_file)}")
print(f"Log file {os.path.join(self.base_folder, self.backup_folder,self.tar_file+'.log')}")
with open(os.path.join(self.base_folder, self.backup_folder,self.tar_file+".md5"), "w") as fp_md5:
print(
f"\nWrote {os.path.join(self.base_folder, self.backup_folder,self.tar_file)}"
)
print(
f"Log file {os.path.join(self.base_folder, self.backup_folder,self.tar_file+'.log')}"
)
with open(
os.path.join(self.base_folder, self.backup_folder, self.tar_file + ".md5"),
"w",
) as fp_md5:
fp_md5.write(f"{md5.hexdigest()} {self.tar_file}\n")
if not success:
with open(os.path.join(self.base_folder, self.backup_folder,self.tar_file+".log")) as f:
print(f.read(),end='')
with open(
os.path.join(
self.base_folder, self.backup_folder, self.tar_file + ".log"
)
) as f:
print(f.read(), end="")
print(f"Exit code: {exitcode}")
return success
def write_config(self):
conf = json.dumps(vars(self.options))
with open(self.config_file, "wt") as fp:
fp.write(
@@ -198,7 +218,6 @@ tar-backup \\
def get_opts():
parser = ArgumentParser(
description="Backup utility using tar and ssh.",
)