mirror of
https://github.com/ZettaIO/restic-compose-backup.git
synced 2025-10-10 12:20:58 +00:00
Compare commits
9 Commits
0.6.0
...
8263f3ef7f
Author | SHA1 | Date | |
---|---|---|---|
|
8263f3ef7f | ||
|
1009a2449f | ||
|
e6ca4aa9ca | ||
|
093dab93ca | ||
|
405bd4af15 | ||
|
28dda6b09d | ||
|
b400138b73 | ||
|
b52655a23b | ||
|
323e299b7e |
24
.readthedocs.yaml
Normal file
24
.readthedocs.yaml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Read the Docs configuration file for Sphinx projects
|
||||||
|
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
||||||
|
|
||||||
|
# Required
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
# Set the OS, Python version and other tools you might need
|
||||||
|
build:
|
||||||
|
os: ubuntu-22.04
|
||||||
|
tools:
|
||||||
|
python: "3.10"
|
||||||
|
|
||||||
|
# Build documentation in the "docs/" directory with Sphinx
|
||||||
|
sphinx:
|
||||||
|
configuration: docs/conf.py
|
||||||
|
|
||||||
|
# Optionally build your docs in additional formats such as PDF and ePub
|
||||||
|
# formats:
|
||||||
|
# - pdf
|
||||||
|
# - epub
|
||||||
|
|
||||||
|
python:
|
||||||
|
install:
|
||||||
|
- requirements: docs/requirements.txt
|
@@ -1,10 +1,9 @@
|
|||||||
version: '3.7'
|
|
||||||
services:
|
services:
|
||||||
backup:
|
backup:
|
||||||
build: ./src
|
build: ./src
|
||||||
env_file:
|
env_file:
|
||||||
- restic_compose_backup.env
|
- restic_compose_backup.env
|
||||||
- alerts.env
|
# - alerts.env
|
||||||
labels:
|
labels:
|
||||||
restic-compose-backup.volumes: true
|
restic-compose-backup.volumes: true
|
||||||
restic-compose-backup.volumes.include: 'src'
|
restic-compose-backup.volumes.include: 'src'
|
||||||
@@ -32,7 +31,7 @@ services:
|
|||||||
- SOME_VALUE=test
|
- SOME_VALUE=test
|
||||||
- ANOTHER_VALUE=1
|
- ANOTHER_VALUE=1
|
||||||
|
|
||||||
mysql:
|
mysql5:
|
||||||
image: mysql:5
|
image: mysql:5
|
||||||
labels:
|
labels:
|
||||||
restic-compose-backup.mysql: true
|
restic-compose-backup.mysql: true
|
||||||
@@ -42,7 +41,19 @@ services:
|
|||||||
- MYSQL_USER=myuser
|
- MYSQL_USER=myuser
|
||||||
- MYSQL_PASSWORD=mypassword
|
- MYSQL_PASSWORD=mypassword
|
||||||
volumes:
|
volumes:
|
||||||
- mysqldata:/var/lib/mysql
|
- mysqldata5:/var/lib/mysql
|
||||||
|
|
||||||
|
mysql8:
|
||||||
|
image: mysql:8
|
||||||
|
labels:
|
||||||
|
restic-compose-backup.mysql: true
|
||||||
|
environment:
|
||||||
|
- MYSQL_ROOT_PASSWORD=my-secret-pw
|
||||||
|
- MYSQL_DATABASE=mydb
|
||||||
|
- MYSQL_USER=myuser
|
||||||
|
- MYSQL_PASSWORD=mypassword
|
||||||
|
volumes:
|
||||||
|
- mysqldata8:/var/lib/mysql
|
||||||
|
|
||||||
mariadb:
|
mariadb:
|
||||||
image: mariadb:10
|
image: mariadb:10
|
||||||
@@ -68,7 +79,8 @@ services:
|
|||||||
- pgdata:/var/lib/postgresql/data
|
- pgdata:/var/lib/postgresql/data
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
mysqldata:
|
mysqldata5:
|
||||||
|
mysqldata8:
|
||||||
mariadbdata:
|
mariadbdata:
|
||||||
pgdata:
|
pgdata:
|
||||||
|
|
||||||
|
69
extras/example-rclone-backend/backup.env
Normal file
69
extras/example-rclone-backend/backup.env
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
|
||||||
|
DOCKER_HOST=unix://var/run/docker.sock
|
||||||
|
# DOCKER_TLS_VERIFY=1
|
||||||
|
# DOCKER_CERT_PATH=''
|
||||||
|
|
||||||
|
INCLUDE_PROJECT_NAME=false
|
||||||
|
EXCLUDE_BIND_MOUNTS=false
|
||||||
|
|
||||||
|
# storj bucket must exist
|
||||||
|
RESTIC_REPOSITORY=rclone:uplink:mybucket
|
||||||
|
RESTIC_PASSWORD="password"
|
||||||
|
|
||||||
|
RCLONE_CONFIG_UPLINK_TYPE=storj
|
||||||
|
# access grant must have permission to use bucket
|
||||||
|
RCLONE_CONFIG_UPLINK_ACCESS_GRANT=
|
||||||
|
|
||||||
|
RESTIC_KEEP_DAILY=7
|
||||||
|
RESTIC_KEEP_WEEKLY=4
|
||||||
|
RESTIC_KEEP_MONTHLY=12
|
||||||
|
RESTIC_KEEP_YEARLY=3
|
||||||
|
|
||||||
|
LOG_LEVEL=info
|
||||||
|
CRON_SCHEDULE="10 2 * * *"
|
||||||
|
|
||||||
|
# EMAIL_HOST=
|
||||||
|
# EMAIL_PORT=
|
||||||
|
# EMAIL_HOST_USER=
|
||||||
|
# EMAIL_HOST_PASSWORD=
|
||||||
|
# EMAIL_SEND_TO=
|
||||||
|
|
||||||
|
# DISCORD_WEBHOOK=u
|
||||||
|
|
||||||
|
# Various env vars for restic : https://restic.readthedocs.io/en/stable/040_backup.html#environment-variables
|
||||||
|
# RESTIC_REPOSITORY Location of repository (replaces -r)
|
||||||
|
# RESTIC_PASSWORD_FILE Location of password file (replaces --password-file)
|
||||||
|
# RESTIC_PASSWORD The actual password for the repository
|
||||||
|
#
|
||||||
|
# AWS_ACCESS_KEY_ID Amazon S3 access key ID
|
||||||
|
# AWS_SECRET_ACCESS_KEY Amazon S3 secret access key
|
||||||
|
#
|
||||||
|
# ST_AUTH Auth URL for keystone v1 authentication
|
||||||
|
# ST_USER Username for keystone v1 authentication
|
||||||
|
# ST_KEY Password for keystone v1 authentication
|
||||||
|
#
|
||||||
|
# OS_AUTH_URL Auth URL for keystone authentication
|
||||||
|
# OS_REGION_NAME Region name for keystone authentication
|
||||||
|
# OS_USERNAME Username for keystone authentication
|
||||||
|
# OS_PASSWORD Password for keystone authentication
|
||||||
|
# OS_TENANT_ID Tenant ID for keystone v2 authentication
|
||||||
|
# OS_TENANT_NAME Tenant name for keystone v2 authentication
|
||||||
|
#
|
||||||
|
# OS_USER_DOMAIN_NAME User domain name for keystone authentication
|
||||||
|
# OS_PROJECT_NAME Project name for keystone authentication
|
||||||
|
# OS_PROJECT_DOMAIN_NAME PRoject domain name for keystone authentication
|
||||||
|
#
|
||||||
|
# OS_STORAGE_URL Storage URL for token authentication
|
||||||
|
# OS_AUTH_TOKEN Auth token for token authentication
|
||||||
|
#
|
||||||
|
# B2_ACCOUNT_ID Account ID or applicationKeyId for Backblaze B2
|
||||||
|
# B2_ACCOUNT_KEY Account Key or applicationKey for Backblaze B2
|
||||||
|
#
|
||||||
|
# AZURE_ACCOUNT_NAME Account name for Azure
|
||||||
|
# AZURE_ACCOUNT_KEY Account key for Azure
|
||||||
|
#
|
||||||
|
# GOOGLE_PROJECT_ID Project ID for Google Cloud Storage
|
||||||
|
# GOOGLE_APPLICATION_CREDENTIALS Application Credentials for Google Cloud Storage (e.g. $HOME/.config/gs-secret-restic-key.json)
|
||||||
|
#
|
||||||
|
# RCLONE_BWLIMIT rclone bandwidth limit
|
||||||
|
# RCLONE_VERBOSE=1 # 2 for -vv
|
23
extras/example-rclone-backend/compose.yaml
Normal file
23
extras/example-rclone-backend/compose.yaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
services:
|
||||||
|
backup:
|
||||||
|
build: ../../src
|
||||||
|
env_file:
|
||||||
|
- backup.env
|
||||||
|
labels:
|
||||||
|
restic-compose-backup.volumes: false
|
||||||
|
volumes:
|
||||||
|
# Map in docker socket
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
# Map restic cache
|
||||||
|
- ./restic_cache:/cache
|
||||||
|
postgres:
|
||||||
|
image: postgres:12
|
||||||
|
env_file:
|
||||||
|
- postgres.env
|
||||||
|
labels:
|
||||||
|
restic-compose-backup.postgres: true
|
||||||
|
volumes:
|
||||||
|
- pgdata:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pgdata:
|
3
extras/example-rclone-backend/postgres.env
Normal file
3
extras/example-rclone-backend/postgres.env
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
POSTGRES_USER=pguser
|
||||||
|
POSTGRES_PASSWORD=pgpassword
|
||||||
|
POSTGRES_DB=test
|
@@ -1,10 +1,22 @@
|
|||||||
FROM restic/restic:0.9.6
|
FROM rclone/rclone:1 AS rclone
|
||||||
|
|
||||||
RUN apk update && apk add python3 dcron mariadb-client postgresql-client
|
FROM restic/restic:0.16.4 AS restic
|
||||||
|
|
||||||
|
FROM python:3.12-alpine
|
||||||
|
|
||||||
|
COPY --from=rclone /usr/local/bin/rclone /usr/local/bin/rclone
|
||||||
|
COPY --from=restic /usr/bin/restic /usr/local/bin/restic
|
||||||
|
|
||||||
|
RUN apk update \
|
||||||
|
&& apk add \
|
||||||
|
dcron \
|
||||||
|
mariadb-client \
|
||||||
|
postgresql-client \
|
||||||
|
mariadb-connector-c-dev
|
||||||
|
|
||||||
ADD . /restic-compose-backup
|
ADD . /restic-compose-backup
|
||||||
WORKDIR /restic-compose-backup
|
WORKDIR /restic-compose-backup
|
||||||
RUN pip3 install -U pip setuptools wheel && pip3 install -e .
|
RUN pip install -U pip setuptools wheel && pip install .
|
||||||
ENV XDG_CACHE_HOME=/cache
|
ENV XDG_CACHE_HOME=/cache
|
||||||
|
|
||||||
ENTRYPOINT []
|
ENTRYPOINT []
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Dump all env vars so we can source them in cron jobs
|
# Dump all env vars so we can source them in cron jobs
|
||||||
printenv | sed 's/^\(.*\)$/export \1/g' > /env.sh
|
rcb dump-env > /env.sh
|
||||||
|
|
||||||
# Write crontab
|
# Write crontab
|
||||||
rcb crontab > crontab
|
rcb crontab > crontab
|
||||||
|
@@ -1 +1 @@
|
|||||||
__version__ = '0.6.0'
|
__version__ = '0.7.1'
|
||||||
|
@@ -15,7 +15,7 @@ class SMTPAlert(BaseAlert):
|
|||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
self.user = user
|
self.user = user
|
||||||
self.password = password
|
self.password = password or ""
|
||||||
self.to = to
|
self.to = to
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -34,7 +34,7 @@ class SMTPAlert(BaseAlert):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def properly_configured(self) -> bool:
|
def properly_configured(self) -> bool:
|
||||||
return self.host and self.port and self.user and self.password and len(self.to) > 0
|
return self.host and self.port and self.user and len(self.to) > 0
|
||||||
|
|
||||||
def send(self, subject: str = None, body: str = None, alert_type: str = 'INFO'):
|
def send(self, subject: str = None, body: str = None, alert_type: str = 'INFO'):
|
||||||
# send_mail("Hello world!")
|
# send_mail("Hello world!")
|
||||||
|
@@ -51,6 +51,9 @@ def main():
|
|||||||
elif args.action == "crontab":
|
elif args.action == "crontab":
|
||||||
crontab(config)
|
crontab(config)
|
||||||
|
|
||||||
|
elif args.action == "dump-env":
|
||||||
|
dump_env()
|
||||||
|
|
||||||
# Random test stuff here
|
# Random test stuff here
|
||||||
elif args.action == "test":
|
elif args.action == "test":
|
||||||
nodes = utils.get_swarm_nodes()
|
nodes = utils.get_swarm_nodes()
|
||||||
@@ -290,6 +293,14 @@ def crontab(config):
|
|||||||
print(cron.generate_crontab(config))
|
print(cron.generate_crontab(config))
|
||||||
|
|
||||||
|
|
||||||
|
def dump_env():
|
||||||
|
"""Dump all environment variables to a script that can be sourced from cron"""
|
||||||
|
print("#!/bin/bash")
|
||||||
|
print("# This file was generated by restic-compose-backup")
|
||||||
|
for key, value in os.environ.items():
|
||||||
|
print("export {}='{}'".format(key, value))
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(prog='restic_compose_backup')
|
parser = argparse.ArgumentParser(prog='restic_compose_backup')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -303,6 +314,7 @@ def parse_args():
|
|||||||
'cleanup',
|
'cleanup',
|
||||||
'version',
|
'version',
|
||||||
'crontab',
|
'crontab',
|
||||||
|
'dump-env',
|
||||||
'test',
|
'test',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@@ -41,6 +41,7 @@ class MariadbContainer(Container):
|
|||||||
f"--port={creds['port']}",
|
f"--port={creds['port']}",
|
||||||
f"--user={creds['username']}",
|
f"--user={creds['username']}",
|
||||||
"--all-databases",
|
"--all-databases",
|
||||||
|
"--no-tablespaces",
|
||||||
]
|
]
|
||||||
|
|
||||||
def backup(self):
|
def backup(self):
|
||||||
@@ -100,6 +101,7 @@ class MysqlContainer(Container):
|
|||||||
f"--port={creds['port']}",
|
f"--port={creds['port']}",
|
||||||
f"--user={creds['username']}",
|
f"--user={creds['username']}",
|
||||||
"--all-databases",
|
"--all-databases",
|
||||||
|
"--no-tablespaces",
|
||||||
]
|
]
|
||||||
|
|
||||||
def backup(self):
|
def backup(self):
|
||||||
|
@@ -3,12 +3,15 @@ from setuptools import setup, find_namespace_packages
|
|||||||
setup(
|
setup(
|
||||||
name="restic-compose-backup",
|
name="restic-compose-backup",
|
||||||
url="https://github.com/ZettaIO/restic-compose-backup",
|
url="https://github.com/ZettaIO/restic-compose-backup",
|
||||||
version="0.6.0",
|
version="0.7.1",
|
||||||
author="Einar Forselv",
|
author="Einar Forselv",
|
||||||
author_email="eforselv@gmail.com",
|
author_email="eforselv@gmail.com",
|
||||||
packages=find_namespace_packages(include=['restic_compose_backup']),
|
packages=find_namespace_packages(include=[
|
||||||
|
'restic_compose_backup',
|
||||||
|
'restic_compose_backup.*',
|
||||||
|
]),
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'docker==4.1.*',
|
'docker~=7.1.0',
|
||||||
],
|
],
|
||||||
entry_points={'console_scripts': [
|
entry_points={'console_scripts': [
|
||||||
'restic-compose-backup = restic_compose_backup.cli:main',
|
'restic-compose-backup = restic_compose_backup.cli:main',
|
||||||
|
Reference in New Issue
Block a user