Last active
August 29, 2015 14:03
-
-
Save llazzaro/051d5ca4ee78286e78cf to your computer and use it in GitHub Desktop.
Fabric script for Postgres backup
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
import os | |
import time | |
from fabric.contrib.files import exists | |
from fabric.api import ( | |
env, | |
require, | |
run, | |
get, | |
sudo | |
) | |
def vps(): | |
env.hosts = ['vps_address'] | |
env.user = 'user' | |
def backup(): | |
require('hosts', provided_by=[vps]) | |
for host in env.hosts: | |
date = time.strftime('%Y%m%d%H%M%S') | |
fname = '/tmp/{host}-backup-{date}.xz'.format(**{ | |
'host': host, | |
'date': date, | |
}) | |
if exists(fname): | |
run('rm "{0}"'.format(fname)) | |
sudo('cd; pg_dumpall | xz > {0}'.format(fname), user='postgres') | |
get(fname, os.path.basename(fname)) | |
sudo('rm "{0}"'.format(fname), user='postgres') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment