2015-12-25, 12:32
Bislang habe ich Subversion immer auf einem externen Virtual-Root Server (1und1) betrieben, da ich aber auch ein Synology NAS habe, kann ich dies auch zuhause erledigen.
Zur Datensicherung der Repositories nutze ich ein Shellskript, das die jeweils aktuellste Version eines Repos in eine Datei dumpt, die dann über Amazon S3 in der Cloud gesichert wird.
Der SVN-Server wurde über den App-Store des NAS heruntergeladen und installiert
Im Aufgabenplaner wird das Dump-Skript nachts aufgerufen
Das Skript dumpt jeweils die HEAD-Version in die entsprechende Datei
NAS> more svnbackupper.sh
#!/bin/ash
for i in $( ls /volume2/svn/); do
svnadmin dump /volume2/svn/$i -rHEAD > /volume1/backups/synosvnbackups/$i.dump
done
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website
2013-01-03, 16:02
I am a regular user of Subversion, all my important TeX files are stored in a SVN repository. SVN has a few builtin hooks, which means at certain events certain scripts are called. The following templates can be found in the hooks subdirectory of the server repository:
- post-commit.tmpl
- post-lock.tmpl
- post-revprop-change.tmpl
- post-unlock.tmpl
- pre-commit.tmpl
- pre-lock.tmpl
- pre-revprop-change.tmpl
- pre-unlock.tmpl
- start-commit.tmpl
It does not matter in what kind of language the scripts are written, Subversion only cares if an executable script (or *.exe file with this name) is present (remove ‚.tmpl‘ at the end of a script to activate it). Today, after reading http://palita.net/2011/08/24/svn-hooks-automatischer-checkout-nach-commits/, I was interested in writing a small Python script which notifies me if a commit has taken place. Based on some e-mail script from http://segfault.in/2010/12/sending-gmail-from-python/ and the argparse tutorial I managed to finish this script in just a few minutes. argparse is needed since Subversion calls the post-commit
script with two parameters, the path to the repository and the version of the commit.
One note on the Google password: It is recommended to use application-specific passwords, see http://support.google.com/mail/bin/answer.py?hl=en&answer=1173270 for details.
#!/usr/bin/python
import smtplib # part of standard installation
import argparse # not part of standard installation
parser = argparse.ArgumentParser()
parser.add_argument("path", help="path to the repository on the server")
parser.add_argument("version", help="version of the commit")
args = parser.parse_args()
print args.path
print args.version
server = 'smtp.gmail.com'
port = 587
sender = '<sender mail address>'
recipient = '<receiver mail address>'
password = "<password>"
subject = 'SVN Commit'
body = 'SVN Commit: '
body = body + args.path + ' ' + args.version
headers = ["From: " + sender,
"Subject: " + subject,
"To: " + recipient,
"MIME-Version: 1.0",
"Content-Type: text/html"]
headers = "\r\n".join(headers)
session = smtplib.SMTP(server, port)
session.ehlo()
session.starttls()
session.ehlo
session.login(sender, password)
session.sendmail(sender, recipient, headers + "\r\n\r\n" + body)
session.quit() |
#!/usr/bin/python
import smtplib # part of standard installation
import argparse # not part of standard installation
parser = argparse.ArgumentParser()
parser.add_argument("path", help="path to the repository on the server")
parser.add_argument("version", help="version of the commit")
args = parser.parse_args()
print args.path
print args.version
server = 'smtp.gmail.com'
port = 587
sender = '<sender mail address>'
recipient = '<receiver mail address>'
password = "<password>"
subject = 'SVN Commit'
body = 'SVN Commit: '
body = body + args.path + ' ' + args.version
headers = ["From: " + sender,
"Subject: " + subject,
"To: " + recipient,
"MIME-Version: 1.0",
"Content-Type: text/html"]
headers = "\r\n".join(headers)
session = smtplib.SMTP(server, port)
session.ehlo()
session.starttls()
session.ehlo
session.login(sender, password)
session.sendmail(sender, recipient, headers + "\r\n\r\n" + body)
session.quit()
Deutsche Zusammenfassung: Subversion stellt gewisse Einsprungspunkte bereit, zu denen man eigene Skripte ausführen kann. Mit Python lässt sich recht einfach ein Skript schreiben, das einen Nutzer über z.B. ein Commit informiert.
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website