mirror of
https://github.com/ZettaIO/restic-compose-backup.git
synced 2025-09-28 14:45:23 +00:00
Rename project
This commit is contained in:
72
restic_compose_backup/restic.py
Normal file
72
restic_compose_backup/restic.py
Normal file
@@ -0,0 +1,72 @@
|
||||
"""
|
||||
Restic commands
|
||||
"""
|
||||
import logging
|
||||
from typing import List
|
||||
from subprocess import Popen, PIPE
|
||||
from restic_compose_backup import commands
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def init_repo(repository: str):
|
||||
"""
|
||||
Attempt to initialize the repository.
|
||||
Doing this after the repository is initialized
|
||||
"""
|
||||
return commands.run(restic(repository, [
|
||||
"init",
|
||||
]))
|
||||
|
||||
|
||||
def backup_files(repository: str, source='/backup'):
|
||||
return commands.run(restic(repository, [
|
||||
"--verbose",
|
||||
"backup",
|
||||
source,
|
||||
]))
|
||||
|
||||
|
||||
def backup_from_stdin(repository: str, filename: str, source_command: List[str]):
|
||||
"""
|
||||
Backs up from stdin running the source_command passed in.
|
||||
It will appear in restic with the filename (including path) passed in.
|
||||
"""
|
||||
dest_command = restic(repository, [
|
||||
'backup',
|
||||
'--stdin',
|
||||
'--stdin-filename',
|
||||
filename,
|
||||
])
|
||||
|
||||
# pipe source command into dest command
|
||||
source_process = Popen(source_command, stdout=PIPE)
|
||||
dest_process = Popen(dest_command, stdin=source_process.stdout)
|
||||
dest_process.communicate()
|
||||
|
||||
# Ensure both processes exited with code 0
|
||||
source_exit, dest_exit = source_process.poll(), dest_process.poll()
|
||||
return 0 if (source_exit == 0 and dest_exit == 0) else 1
|
||||
|
||||
|
||||
def snapshots(repository: str):
|
||||
return commands.run(restic(repository, [
|
||||
"snapshots",
|
||||
]))
|
||||
|
||||
|
||||
def check(repository: str):
|
||||
return commands.run(restic(repository, [
|
||||
"check",
|
||||
]))
|
||||
|
||||
|
||||
def restic(repository: str, args: List[str]):
|
||||
"""Generate restic command"""
|
||||
return [
|
||||
"restic",
|
||||
"--cache-dir",
|
||||
"/restic_cache",
|
||||
"-r",
|
||||
repository,
|
||||
] + args
|
Reference in New Issue
Block a user