Skip to content

Commit 79040c1

Browse files
committed
Added Fabric 0.9beta presentation and code samples
1 parent b4176c0 commit 79040c1

File tree

6 files changed

+122
-0
lines changed

6 files changed

+122
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "20090512/kogakure-de"]
22
path = 20090512/kogakure-de
33
url = git://github.com/kogakure/kogakure-de.git
4+
[submodule "20091027/fabric-0.9beta/gist-205829"]
5+
path = 20091027/fabric-0.9beta/gist-205829
6+
url = git://gist.github.com/205829.git
1.2 MB
Binary file not shown.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
from __future__ import with_statement # needed for python 2.5
5+
from fabric.api import *
6+
7+
from time import *
8+
lt = localtime()
9+
10+
env.hosts = ['domain.cpm']
11+
env.postgres_bin = '/usr/local/pgsql/bin'
12+
env.backup_dir = '/home/user/backup'
13+
env.backup_dir_local = '/Users/user/Backups'
14+
env.date = strftime("%Y-%m-%d", lt)
15+
16+
def backup():
17+
"""
18+
Start the backup of databases and files, then copy gziped tars to my
19+
local harddrive.
20+
"""
21+
require('hosts')
22+
require('backup_dir')
23+
require('backup_dir_local')
24+
require('date')
25+
backup_postgres()
26+
backup_mysql()
27+
backup_files()
28+
get_files()
29+
30+
def backup_postgres():
31+
"""
32+
Create a database dump of my PostgreSQL database
33+
"""
34+
with cd('%(backup_dir)s' % env):
35+
with cd('db'):
36+
run('/usr/local/pgsql/bin/pg_dump database_postgres -U user > %(date)s-database_postgres.sql' % env, pty=True)
37+
run('gzip -f %(date)s-database_postgres.sql' % env, pty=True)
38+
39+
def backup_mysql():
40+
"""
41+
Create a database dump of my MySQL databases
42+
"""
43+
with cd('%(backup_dir)s' % env):
44+
with cd('db'):
45+
run('mysqldump --user=user --password="secret" --add-drop-table database_mysql --opt -h localhost > %(date)s-database_mysql.sql' % env, pty=True)
46+
run('gzip -f %(date)s-database_mysql.sql' % env, pty=True)
47+
48+
def backup_files():
49+
"""
50+
Create a backup of all files on the server
51+
"""
52+
with cd('%(backup_dir)s' % env):
53+
with cd('files'):
54+
run('tar -czvpf %(date)s-backup_django.tgz /home/user/django/ --exclude=cache' % env, pty=True)
55+
run('tar -czvpf %(date)s-backup_home.tgz /home/user/ --exclude=django --exclude=cache --exclude=logs --exclude=backup --exclude=src --exclude=transfer' % env, pty=True)
56+
57+
def get_files():
58+
get('%(backup_dir)s/db/%(date)s-database_postgres.sql.gz' % env,'%(backup_dir_local)s/Datenbanken/' % env)
59+
get('%(backup_dir)s/db/%(date)s-database_mysql.sql.gz' % env,'%(backup_dir_local)s/Datenbanken/' % env)
60+
get('%(backup_dir)s/files/%(date)s-backup_home.tgz' % env,'%(backup_dir_local)s/Websites/' % env)
61+
get('%(backup_dir)s/files/%(date)s-backup_django.tgz' % env,'%(backup_dir_local)s/Websites/' % env)
62+
local('cd %(backup_dir_local)s/Websites/; mv %(date)s-backup_webapps.tgz backup_webapps.tgz; mv %(date)s-backup_home.tgz backup_home.tgz' % env)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
from __future__ import with_statement # needed for python 2.5
5+
from fabric.api import env, local, run, require
6+
7+
env.hosts = ['domain.de']
8+
env.path = '/home/user/apache2/bin'
9+
env.project_path = '/home/user/project'
10+
env.memcached_ip = '127.0.0.1'
11+
env.memcached_port = '1234'
12+
env.memcached_size = '20' # in MByte
13+
14+
def deploy():
15+
"Lokale Änderungen pushen, Änderungen pullen auf server, Server neustarten"
16+
require('hosts')
17+
require('path')
18+
require('project_path')
19+
local('git push;')
20+
with ('cd %(project_path)s/' % env):
21+
run('git pull', pty=True)
22+
run('delpyc', pty=True)
23+
restart_server()
24+
25+
def stop_server():
26+
"Apache stoppen"
27+
run('%(path)s/stop' % env, pty=True)
28+
29+
def start_server():
30+
"Apache starten"
31+
run('%(path)s/start' % env, pty=True)
32+
33+
def restart_server():
34+
"Apache neustarten"
35+
with cd('%(path)s/' % env):
36+
run('stop' % pty=True)
37+
run('start' % pty=True)
38+
39+
def restart_memcached():
40+
"Memcached neustarten"
41+
run('kill `pgrep -u $LOGNAME memcached`' % env, pty=True)
42+
run('/usr/local/bin/memcached -d -l %(memcached_ip)s -m %(memcached_size)s -p %(memcached_port)s' % env, pty=True)
43+
restart_server()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
from fabric.api import env, rsync_project
5+
6+
env.hosts = ['domain.com']
7+
env.path = '/home/user/project/'
8+
9+
def sync():
10+
"""
11+
Synchronize project with webserver
12+
"""
13+
rsync_project(env.path, delete=True, exclude=['*.pyc','*.py','.DS_Store'])
Submodule gist-205829 added at b259bc3

0 commit comments

Comments
 (0)