8 Commits
0.3.1 ... 0.3.3

Author SHA1 Message Date
Einar Forselv
758c3075f1 Bump version 2019-12-06 09:09:05 +01:00
Einar Forselv
9cad6a5c71 Update cli.py 2019-12-06 09:08:48 +01:00
Einar Forselv
4ebe16af14 Properly get the container exit code 2019-12-06 08:21:21 +01:00
Einar Forselv
fd87ddc388 More logging during backup 2019-12-06 08:21:06 +01:00
Einar Forselv
2cbc5aa6fa bump version 2019-12-06 07:36:30 +01:00
Einar Forselv
ffa2dfc119 rcb version 2019-12-06 07:35:14 +01:00
Einar Forselv
cfc92b2284 Bug: The log stream from docker can be str or bytes
We don't know why this is the case..
2019-12-06 07:30:39 +01:00
Einar Forselv
216202dec7 Bump version 2019-12-06 06:07:03 +01:00
6 changed files with 28 additions and 11 deletions

View File

@@ -22,8 +22,7 @@ copyright = '2019, Zetta.IO Technology AS'
author = 'Zetta.IO Technology AS' author = 'Zetta.IO Technology AS'
# The full version, including alpha/beta/rc tags # The full version, including alpha/beta/rc tags
release = '0.3.0' release = '0.3.3'
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------

View File

@@ -2,6 +2,7 @@
- Update version in `setup.py` - Update version in `setup.py`
- Update version in `docs/conf.py` - Update version in `docs/conf.py`
- Update version in `restic_compose_backup/__init__.py`
- Build and tag image - Build and tag image
- push: `docker push zettaio/restic-compose-backup:<version>` - push: `docker push zettaio/restic-compose-backup:<version>`
- Ensure RTD has new docs published - Ensure RTD has new docs published
@@ -12,9 +13,9 @@ When releasing a bugfix version we need to update the
main image as well. main image as well.
```bash ```bash
docker build . --tag zettaio/restic-compose-backup:0.3 docker build src --tag zettaio/restic-compose-backup:0.3
docker build . --tag zettaio/restic-compose-backup:0.3.1 docker build src --tag zettaio/restic-compose-backup:0.3.3
docker push zettaio/restic-compose-backup:0.3 docker push zettaio/restic-compose-backup:0.3
docker push zettaio/restic-compose-backup:0.3.1 docker push zettaio/restic-compose-backup:0.3.3
``` ```

View File

@@ -0,0 +1 @@
__version__ = '0.3.3'

View File

@@ -35,7 +35,13 @@ def run(image: str = None, command: str = None, volumes: dict = None,
line = "" line = ""
while True: while True:
try: try:
line += next(stream).decode() # TODO: figure out why..
# Apparently the stream can be bytes or strings.
data = next(stream)
if isinstance(data, bytes):
line += data.decode()
elif isinstance(data, str):
line += data
if line.endswith('\n'): if line.endswith('\n'):
break break
except StopIteration: except StopIteration:
@@ -51,9 +57,9 @@ def run(image: str = None, command: str = None, volumes: dict = None,
fd.write('\n') fd.write('\n')
logger.info(line) logger.info(line)
container.wait()
container.reload() container.reload()
logger.debug("Container ExitCode %s", container.attrs['State']['ExitCode']) logger.debug("Container ExitCode %s", container.attrs['State']['ExitCode'])
container.stop()
container.remove() container.remove()
return container.attrs['State']['ExitCode'] return container.attrs['State']['ExitCode']

View File

@@ -42,6 +42,10 @@ def main():
elif args.action == 'alert': elif args.action == 'alert':
alert(config, containers) alert(config, containers)
elif args.action == 'version':
import restic_compose_backup
print(restic_compose_backup.__version__)
def status(config, containers): def status(config, containers):
"""Outputs the backup config for the compose setup""" """Outputs the backup config for the compose setup"""
@@ -139,13 +143,15 @@ def start_backup_process(config, containers):
vol_result = restic.backup_files(config.repository, source='/volumes') vol_result = restic.backup_files(config.repository, source='/volumes')
logger.debug('Volume backup exit code: %s', vol_result) logger.debug('Volume backup exit code: %s', vol_result)
if vol_result != 0: if vol_result != 0:
logger.error('Backup command exited with non-zero code: %s', vol_result) logger.error('Volume backup exited with non-zero code: %s', vol_result)
errors = True errors = True
except Exception as ex: except Exception as ex:
logger.error('Exception raised during volume backup')
logger.exception(ex) logger.exception(ex)
errors = True errors = True
# back up databases # back up databases
logger.info('Backing up databases')
for container in containers.containers_for_backup(): for container in containers.containers_for_backup():
if container.database_backup_enabled: if container.database_backup_enabled:
try: try:
@@ -161,14 +167,18 @@ def start_backup_process(config, containers):
errors = True errors = True
if errors: if errors:
logger.error('Exit code: %s', errors)
exit(1) exit(1)
# Only run cleanup if backup was successful # Only run cleanup if backup was successful
result = cleanup(config, container) result = cleanup(config, container)
logger.debug('cleanup exit code: %s', errors) logger.debug('cleanup exit code: %s', result)
if result != 0: if result != 0:
logger.error('Exit code: %s', result)
exit(1) exit(1)
logger.info('Backup completed')
def cleanup(config, containers): def cleanup(config, containers):
"""Run forget / prune to minimize storage space""" """Run forget / prune to minimize storage space"""
@@ -205,7 +215,7 @@ def parse_args():
parser = argparse.ArgumentParser(prog='restic_compose_backup') parser = argparse.ArgumentParser(prog='restic_compose_backup')
parser.add_argument( parser.add_argument(
'action', 'action',
choices=['status', 'snapshots', 'backup', 'start-backup-process', 'alert', 'cleanup'], choices=['status', 'snapshots', 'backup', 'start-backup-process', 'alert', 'cleanup', 'version'],
) )
parser.add_argument( parser.add_argument(
'--log-level', '--log-level',

View File

@@ -3,7 +3,7 @@ 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.3.0", version="0.3.3",
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']),