Skip to content

Instantly share code, notes, and snippets.

@silegon
Created August 21, 2012 13:11
Show Gist options
  • Save silegon/3415290 to your computer and use it in GitHub Desktop.
Save silegon/3415290 to your computer and use it in GitHub Desktop.
import os
from fabric.api import run, local, put, cd, env
from time import strftime, localtime
env.hosts = ['silegon@forpm.net']
site_name = "forpm.net"
local_path = "/home/silegon/sites/online/django_silegon"
remote_path = "/home/silegon/sites/online/django_silegon"
server_config_path = os.path.join(remote_path, "extra/server")
def sync_code_remote():
with cd(remote_path):
run("git pull")
run("killall /usr/bin/uwsgi")
with cd(server_config_path):
run("uwsgi -x django_silegon.xml")
def sync_data_remote():
local_media_path = os.path.join(local_path, 'django_silegon/media')
remote_media_path = os.path.join(remote_path, 'django_silegon/media')
now = strftime("%y%m%d%H%M%S",localtime())
file_name = "%s_data.json"%(now)
local_backup_path = os.path.join(local_path, 'extra/backup')
remote_backup_path = os.path.join(remote_path, 'extra/backup')
local("python %s/manage.py dumpdata --exclude contenttypes > %s/%s"%(local_path, local_backup_path, file_name))
put("%s/%s"%(local_backup_path, file_name),remote_backup_path)
run("python %s/manage.py loaddata %s"%(remote_path, os.path.join(remote_backup_path, file_name)))
local("rsync -avz %s/ %s:%s/"%(local_media_path, env.hosts[0], remote_media_path))
run("killall /usr/bin/uwsgi")
with cd(server_config_path):
run("uwsgi -x django_silegon.xml")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment