tar backuper cousin to rsync-backup
This commit is contained in:
@@ -103,7 +103,9 @@ class RSB:
|
|||||||
if os.path.exists(tgt_dir):
|
if os.path.exists(tgt_dir):
|
||||||
raise FileExistsError("Folder {} already exists".format(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):
|
def make_backup(self):
|
||||||
if self.options.no_backup:
|
if self.options.no_backup:
|
||||||
@@ -123,7 +125,6 @@ class RSB:
|
|||||||
return success
|
return success
|
||||||
|
|
||||||
def write_config(self):
|
def write_config(self):
|
||||||
|
|
||||||
conf = json.dumps(vars(self.options))
|
conf = json.dumps(vars(self.options))
|
||||||
with open(self.config_file, "wt") as fp:
|
with open(self.config_file, "wt") as fp:
|
||||||
fp.write(
|
fp.write(
|
||||||
@@ -164,7 +165,6 @@ rsync-backup \\
|
|||||||
|
|
||||||
|
|
||||||
def get_opts():
|
def get_opts():
|
||||||
|
|
||||||
parser = ArgumentParser(
|
parser = ArgumentParser(
|
||||||
description="Minimal incrementive backup utility using rsync and hard links.",
|
description="Minimal incrementive backup utility using rsync and hard links.",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -114,14 +114,24 @@ class TB:
|
|||||||
os.makedirs(os.path.join(self.base_folder, self.backup_folder), exist_ok=True)
|
os.makedirs(os.path.join(self.base_folder, self.backup_folder), exist_ok=True)
|
||||||
print("Backing up")
|
print("Backing up")
|
||||||
|
|
||||||
|
ssh_command = (
|
||||||
ssh_command = [
|
[
|
||||||
"ssh",
|
"ssh",
|
||||||
*shlex.split(self.ssh_args),
|
*shlex.split(self.ssh_args),
|
||||||
] if self.ssh_args else []
|
]
|
||||||
|
if self.ssh_args
|
||||||
|
else []
|
||||||
|
)
|
||||||
|
|
||||||
with open(os.path.join(self.base_folder, self.backup_folder,self.tar_file), "wb") as fp:
|
with open(
|
||||||
with open(os.path.join(self.base_folder, self.backup_folder,self.tar_file+".log"), "w") as fp_log:
|
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 = [
|
command = [
|
||||||
*ssh_command,
|
*ssh_command,
|
||||||
"tar",
|
"tar",
|
||||||
@@ -136,24 +146,34 @@ class TB:
|
|||||||
chunk = p.stdout.read(1048576)
|
chunk = p.stdout.read(1048576)
|
||||||
if len(chunk) == 0:
|
if len(chunk) == 0:
|
||||||
break
|
break
|
||||||
print(f"{i} Mb", end='\r')
|
print(f"{i} Mb", end="\r")
|
||||||
i += 1
|
i += 1
|
||||||
md5.update(chunk)
|
md5.update(chunk)
|
||||||
fp.write(chunk)
|
fp.write(chunk)
|
||||||
exitcode = p.wait()
|
exitcode = p.wait()
|
||||||
success = exitcode in (0, 2)
|
success = exitcode in (0, 2)
|
||||||
print(f"\nWrote {os.path.join(self.base_folder, self.backup_folder,self.tar_file)}")
|
print(
|
||||||
print(f"Log file {os.path.join(self.base_folder, self.backup_folder,self.tar_file+'.log')}")
|
f"\nWrote {os.path.join(self.base_folder, self.backup_folder,self.tar_file)}"
|
||||||
with open(os.path.join(self.base_folder, self.backup_folder,self.tar_file+".md5"), "w") as fp_md5:
|
)
|
||||||
|
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")
|
fp_md5.write(f"{md5.hexdigest()} {self.tar_file}\n")
|
||||||
if not success:
|
if not success:
|
||||||
with open(os.path.join(self.base_folder, self.backup_folder,self.tar_file+".log")) as f:
|
with open(
|
||||||
print(f.read(),end='')
|
os.path.join(
|
||||||
|
self.base_folder, self.backup_folder, self.tar_file + ".log"
|
||||||
|
)
|
||||||
|
) as f:
|
||||||
|
print(f.read(), end="")
|
||||||
print(f"Exit code: {exitcode}")
|
print(f"Exit code: {exitcode}")
|
||||||
return success
|
return success
|
||||||
|
|
||||||
def write_config(self):
|
def write_config(self):
|
||||||
|
|
||||||
conf = json.dumps(vars(self.options))
|
conf = json.dumps(vars(self.options))
|
||||||
with open(self.config_file, "wt") as fp:
|
with open(self.config_file, "wt") as fp:
|
||||||
fp.write(
|
fp.write(
|
||||||
@@ -198,7 +218,6 @@ tar-backup \\
|
|||||||
|
|
||||||
|
|
||||||
def get_opts():
|
def get_opts():
|
||||||
|
|
||||||
parser = ArgumentParser(
|
parser = ArgumentParser(
|
||||||
description="Backup utility using tar and ssh.",
|
description="Backup utility using tar and ssh.",
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user