initial commit
This commit is contained in:
commit
193fee2abe
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"repos": [
|
||||
{
|
||||
"name": "knucles/services/gitea",
|
||||
"paths": ["/home/docker/containers/gitea"]
|
||||
},
|
||||
{
|
||||
"name": "knucles/services/synapse",
|
||||
"paths": ["/home/docker/containers/synapse"]
|
||||
}
|
||||
],
|
||||
"repo_name_prefix": "b2:vivlim-restic:"
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#!/bin/python3
|
||||
|
||||
import json
|
||||
import shlex
|
||||
import subprocess
|
||||
|
||||
restic_bin = '/home/restic/bin/restic'
|
||||
|
||||
init_command = "restic -r %s init"
|
||||
command = "restic -r %s backup --verbose %s"
|
||||
|
||||
def do_backup(repo_name, paths):
|
||||
result = subprocess.run([restic_bin, '-r', repo_name, 'backup', '--verbose'] + paths)
|
||||
|
||||
def init_repo(repo_name):
|
||||
result = subprocess.run([restic_bin, '-r', repo_name, 'init'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
any_errors = len(result.stderr) > 0
|
||||
already_existed = result.stderr.decode('utf-8').strip().endswith('config already exists')
|
||||
|
||||
if any_errors and not already_existed:
|
||||
print(result.stderr.decode('utf-8').strip())
|
||||
return False
|
||||
|
||||
if already_existed:
|
||||
print("Repo already exists")
|
||||
return True
|
||||
print(result.stdout.decode('utf-8').strip())
|
||||
print("Repo was created.")
|
||||
return True
|
||||
|
||||
|
||||
|
||||
with open('backup-config.json') as json_file:
|
||||
data = json.load(json_file)
|
||||
|
||||
repo_name_prefix = data['repo_name_prefix']
|
||||
|
||||
for repo in data['repos']:
|
||||
repo_name = repo_name_prefix + repo['name']
|
||||
print('Repo: ' + repo_name)
|
||||
paths_to_backup = [shlex.quote(p) for p in repo['paths']]
|
||||
print('Backing up paths: ' + ", ".join(paths_to_backup))
|
||||
|
||||
init_result = init_repo(repo_name)
|
||||
|
||||
if not init_result:
|
||||
print('Skipping backup of %s.' % repo_name)
|
||||
continue
|
||||
|
||||
do_backup(repo_name, paths_to_backup)
|
||||
|
Loading…
Reference in New Issue