-
-
Save tboulogne/39f66c5e46d8a24e0184369428b6fbc5 to your computer and use it in GitHub Desktop.
backup files and sql from servers, use fabric python
This file contains hidden or 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 python | |
| # -*- coding: utf-8 -*- | |
| # run: fab backup | |
| __author__ = 'fdcore' | |
| from fabric.api import env, run, get | |
| from datetime import datetime | |
| import os | |
| env.hosts = [ | |
| 'root@0.0.0.0:22', | |
| ] | |
| env.passwords = { | |
| 'root@0.0.0.0:22': 'password', | |
| } | |
| mysql_passwords = { | |
| '0.0.0.0': 'password', | |
| } | |
| date = datetime.now().strftime("%Y-%m-%d") | |
| time = datetime.now().strftime("%H-%M-%S") | |
| def backup(): | |
| run("tar cfvz /tmp/backup.tar.gz /srv/www") | |
| path = "archive/{0}/{1}/".format(env.host, date) | |
| if os.path.exists(path) is False: | |
| os.makedirs(path) | |
| get("/tmp/backup.tar.gz", path+time+"_backup.tar.gz") | |
| run("mysqldump -u root --password '{0}' --all-databases > /tmp/all-database.sql; echo 'y'".format(mysql_passwords[env.host])) | |
| run("gzip /tmp/all-database.sql") | |
| get("/tmp/all-database.sql.gz", path+time+"_backup.sql.gz") | |
| run("rm /tmp/all-database.sql.gz") | |
| run("rm /tmp/backup.tar.gz") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment