restic-compose-backup/restic_volume_backup/restic.py

52 lines
842 B
Python
Raw Normal View History

2019-04-13 17:04:54 +00:00
import os
from subprocess import Popen, PIPE, check_call
2019-04-13 18:12:25 +00:00
def init_repo(repository):
2019-04-13 17:04:54 +00:00
run_command([
"restic",
"-r",
2019-04-13 18:12:25 +00:00
repository,
2019-04-13 17:04:54 +00:00
"init",
])
2019-04-13 18:12:25 +00:00
def backup_volume(repository, volume):
2019-04-13 17:04:54 +00:00
run_command([
"restic",
"-r",
2019-04-13 18:12:25 +00:00
repository,
2019-04-13 17:04:54 +00:00
"--verbose",
"backup",
volume.destination,
])
2019-04-13 18:12:25 +00:00
def snapshots(repository):
2019-04-13 17:04:54 +00:00
run_command([
"restic",
"-r",
2019-04-13 18:12:25 +00:00
repository,
2019-04-13 17:04:54 +00:00
"snapshots",
])
2019-04-13 18:12:25 +00:00
def check(repository):
2019-04-13 17:04:54 +00:00
run_command([
"restic",
"-r",
2019-04-13 18:12:25 +00:00
repository,
2019-04-13 17:04:54 +00:00
"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())