Last active
October 30, 2019 12:54
-
-
Save peterbe/8b25a06e6a1d614a78e1f93dc1a9c9a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import subprocess | |
import datetime | |
import time | |
import os | |
out = subprocess.check_output(["docker", "ps"]).decode("utf-8") | |
docker_id, = [ | |
x.split()[0] for x in out.splitlines() if x.split()[1].startswith("mysql:") | |
] | |
print(docker_id) | |
print("Docker ID", docker_id) | |
today = datetime.datetime.utcnow() | |
outfile = f'../backup.{today.strftime("%Y%m%d")}.sql' | |
with open(outfile, "w") as f: | |
command = [ | |
"docker", | |
"exec", | |
docker_id, | |
"/usr/bin/mysqldump", | |
"-u", | |
"root", | |
"--password=kuma", | |
"developer_mozilla_org", | |
] | |
print(f"Starting... ({' '.join(command)})") | |
t0 = time.time() | |
subprocess.call(command, stdout=f) | |
t1 = time.time() | |
size = os.stat(outfile).st_size | |
print(f"Finished {outfile} ({size / 1024 /1024:.1f}MB) in {t1 - t0:.1f} seconds") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment