restic-compose-backup/restic_volume_backup/restic.py

86 lines
1.6 KiB
Python
Raw Normal View History

"""
Restic commands
"""
2019-11-15 13:23:56 +00:00
import logging
2019-11-12 11:39:49 +00:00
from subprocess import Popen, PIPE
from restic_volume_backup import commands
2019-04-13 17:04:54 +00:00
2019-11-15 13:23:56 +00:00
logger = logging.getLogger(__name__)
2019-04-13 17:04:54 +00:00
2019-04-13 18:12:25 +00:00
def init_repo(repository):
2019-11-15 13:23:56 +00:00
"""
Attempt to initialize the repository.
Doing this after the repository is initialized
"""
return commands.run([
2019-04-13 17:04:54 +00:00
"restic",
2019-11-29 00:25:00 +00:00
"--cache-dir",
"/restic_cache",
2019-04-13 17:04:54 +00:00
"-r",
2019-04-13 18:12:25 +00:00
repository,
2019-04-13 17:04:54 +00:00
"init",
])
2019-11-29 00:25:00 +00:00
def backup_files(repository, source='/backup'):
return commands.run([
2019-04-13 17:04:54 +00:00
"restic",
2019-11-29 00:25:00 +00:00
"--cache-dir",
"/restic_cache",
2019-04-13 17:04:54 +00:00
"-r",
2019-04-13 18:12:25 +00:00
repository,
2019-04-13 17:04:54 +00:00
"--verbose",
"backup",
2019-11-29 00:25:00 +00:00
source,
2019-04-13 17:04:54 +00:00
])
2019-11-29 00:25:00 +00:00
def backup_mysql_all(repository, host, port, user, password, filename):
"""Backup all mysql databases"""
# -h host, -p password
return commands.run([
2019-11-29 00:25:00 +00:00
'mysqldump',
'--host',
host,
'--port',
port,
'--user',
user,
'--password',
password,
'|',
'restic',
'backup',
'--stdin',
'--stdin-filename',
'dump.sql'
])
def backup_mysql_database(repository, host, port, user, password, filename, database):
"""Backup a single database"""
pass
2019-04-13 18:12:25 +00:00
def snapshots(repository):
return commands.run([
2019-04-13 17:04:54 +00:00
"restic",
2019-11-29 00:25:00 +00:00
"--cache-dir",
"/restic_cache",
2019-04-13 17:04:54 +00:00
"-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):
return commands.run([
2019-04-13 17:04:54 +00:00
"restic",
2019-11-29 00:25:00 +00:00
"--cache-dir",
"/restic_cache",
2019-04-13 17:04:54 +00:00
"-r",
2019-04-13 18:12:25 +00:00
repository,
2019-04-13 17:04:54 +00:00
"check",
])