This commit is contained in:
Einar Forselv
2019-04-13 19:04:54 +02:00
commit a3cdb38239
11 changed files with 280 additions and 0 deletions

55
restic-backup/restic.py Normal file
View File

@@ -0,0 +1,55 @@
import os
from subprocess import Popen, PIPE, check_call
def repo_path(container_name):
return "swift:{}:/".format(container_name)
def init_repo(container_name):
run_command([
"restic",
"-r",
repo_path(container_name),
"init",
])
def backup_volume(container_name, volume):
run_command([
"restic",
"-r",
repo_path(container_name),
"--verbose",
"backup",
volume.destination,
])
def snapshots(container_name):
run_command([
"restic",
"-r",
repo_path(container_name),
"snapshots",
])
def check(container_name):
run_command([
"restic",
"-r",
repo_path(container_name),
"check",
])
def run_command(cmd):
child = Popen(cmd, stdout=PIPE, stderr=PIPE)
stdoutdata, stderrdata = child.communicate()
if stdoutdata:
print(stdoutdata.decode())
if stderrdata:
print(stderrdata.decode())