mirror of
https://codeberg.org/vlw/cloud-backup.git
synced 2025-09-14 10:03:40 +02:00
wip(22w9c): add single item backup
This commit is contained in:
parent
ff0b3529e0
commit
d9a6183d63
3 changed files with 56 additions and 3 deletions
30
backup.py
30
backup.py
|
@ -1,5 +1,31 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from src import Backup
|
from src import Backup, file_exists
|
||||||
|
|
||||||
Backup().backup_all()
|
# Back up a single file by path
|
||||||
|
def file_backup():
|
||||||
|
path = sys.argv[2]
|
||||||
|
|
||||||
|
if len(sys.argv) < 3:
|
||||||
|
return print("Invalid argument length: Expected path to file or folder")
|
||||||
|
|
||||||
|
if not file_exists(path):
|
||||||
|
return print(f"File or folder at '{path}' does not exist")
|
||||||
|
|
||||||
|
return Backup().backup_item(path, False)
|
||||||
|
|
||||||
|
def run(method):
|
||||||
|
methods = {
|
||||||
|
"file": file_backup,
|
||||||
|
"all" : Backup().backup_all
|
||||||
|
}
|
||||||
|
|
||||||
|
if method not in methods:
|
||||||
|
return print(f"Invalid argument '{method}'")
|
||||||
|
|
||||||
|
return methods[method]()
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
run(sys.argv[1])
|
||||||
|
else:
|
||||||
|
run("all")
|
23
resolve.py
Normal file
23
resolve.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from src import Database
|
||||||
|
|
||||||
|
class Resolve(Database):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
if self.item_exists(sys.argv[1]):
|
||||||
|
self.path_to_chksum()
|
||||||
|
else:
|
||||||
|
self.chksum_to_path()
|
||||||
|
|
||||||
|
def path_to_chksum(self):
|
||||||
|
print("Something")
|
||||||
|
|
||||||
|
def chksum_to_path(self):
|
||||||
|
print("Something else")
|
||||||
|
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
Resolve()
|
||||||
|
else:
|
||||||
|
print("Invalid argument length: Need at least two")
|
|
@ -16,7 +16,7 @@ class Backup(FileSystem):
|
||||||
self.compress = self.db.get_flag("COMPRESS")
|
self.compress = self.db.get_flag("COMPRESS")
|
||||||
|
|
||||||
# Backup a file or folder
|
# Backup a file or folder
|
||||||
def backup_item(self, item: Union[list, str]) -> bool:
|
def backup_item(self, item: Union[list, str], silent: bool = True) -> bool:
|
||||||
if isinstance(item, str):
|
if isinstance(item, str):
|
||||||
item = self.get_item(item)
|
item = self.get_item(item)
|
||||||
|
|
||||||
|
@ -54,6 +54,10 @@ class Backup(FileSystem):
|
||||||
# Remove temp zip
|
# Remove temp zip
|
||||||
if self.compress:
|
if self.compress:
|
||||||
FileSystem.delete(blob)
|
FileSystem.delete(blob)
|
||||||
|
|
||||||
|
if not silent and not self.has_change:
|
||||||
|
print("✓ | Up to date. No changes found")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Scan TARGET_FOLDER for files and folders to back up
|
# Scan TARGET_FOLDER for files and folders to back up
|
||||||
|
|
Loading…
Add table
Reference in a new issue