mirror of
https://github.com/ZettaIO/restic-compose-backup.git
synced 2025-09-28 14:45:23 +00:00
Proper log streaming
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import docker
|
import docker
|
||||||
|
|
||||||
@@ -14,21 +15,22 @@ def run(image: str = None, command: str = None, volumes: dict = None,
|
|||||||
image,
|
image,
|
||||||
command,
|
command,
|
||||||
labels=labels,
|
labels=labels,
|
||||||
auto_remove=True,
|
# auto_remove=True,
|
||||||
detach=True,
|
detach=True,
|
||||||
environment=enviroment,
|
environment=enviroment,
|
||||||
volumes=volumes,
|
volumes=volumes,
|
||||||
working_dir=os.getcwd(),
|
working_dir=os.getcwd(),
|
||||||
|
tty=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Backup process container:", container.name)
|
print("Backup process container:", container.name)
|
||||||
logs = container.logs(stdout=True, stderr=True, stream=True)
|
log_generator = container.logs(stdout=True, stderr=True, stream=True, follow=True)
|
||||||
try:
|
with open('backup.log', 'w') as fd:
|
||||||
while True:
|
for line in log_generator:
|
||||||
time.sleep(3)
|
line = line.decode()
|
||||||
for line in logs:
|
fd.write(line)
|
||||||
print(line.decode(), end='')
|
print(line, end='')
|
||||||
# Raises requests.exceptions.HTTPError if continer is dead
|
|
||||||
container.top()
|
container.reload()
|
||||||
except Exception as ex:
|
print("ExitCode", container.attrs['State']['ExitCode'])
|
||||||
print("Container stopped")
|
container.remove()
|
||||||
|
Reference in New Issue
Block a user