Merge branch 'master' of ssh://git.onelab.eu/git/infrastructure
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Sun, 26 Sep 2010 12:23:47 +0000 (14:23 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Sun, 26 Sep 2010 12:23:47 +0000 (14:23 +0200)
scripts/5.0-rc15.sh [new file with mode: 0755]
scripts/backup-databases.sh [new file with mode: 0755]
scripts/backup-helper [new file with mode: 0755]
scripts/git-check.sh

diff --git a/scripts/5.0-rc15.sh b/scripts/5.0-rc15.sh
new file mode 100755 (executable)
index 0000000..14023b2
--- /dev/null
@@ -0,0 +1,9 @@
+function liquid () { hostname | grep liquid >& /dev/null ; }
+function reed () { hostname | grep reed >& /dev/null ; }
+function velvet () { hostname | grep velvet >& /dev/null ; }
+
+liquid && /root/bin/vbuild-nightly.sh -m build@onelab.eu -s git://git.onelab.eu/build@5.0-rc15 -d onelab -f f8 -p linux64 -b onelab--5.0-rc15-f8-64
+reed && /root/bin/vbuild-nightly.sh -m build@onelab.eu -s git://git.onelab.eu/build@5.0-rc15 -d onelab -f f12 -p linux64 -b onelab--5.0-rc15-f12-64 -t onelab-k27-tags.mk
+
+velvet && /root/bin/vbuild-nightly.sh -m build@onelab.eu -s git://git.onelab.eu/build@5.0-rc15 -d onelab -f f8 -p linux32 -b onelab--5.0-rc15-f8-32
+liquid && /root/bin/vbuild-nightly.sh -m build@onelab.eu -s git://git.onelab.eu/build@5.0-rc15 -d onelab -f f12 -p linux32 -b onelab--5.0-rc15-f12-32 -t onelab-k27-tags.mk
diff --git a/scripts/backup-databases.sh b/scripts/backup-databases.sh
new file mode 100755 (executable)
index 0000000..2b87947
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+source /etc/backup-helper
+
+DATE=`date +%Y%m%d-%H%M`
+HOST=`hostname -s`
+
+ps -C postmaster 2>&1 >/dev/null
+if [ $? -eq 0 ]; then
+       backup_all_dbs /mnt/backup $HOST $DATE
+fi
+
+# thierry : tmp backup solution on gorillaz
+# note that in addition to the db dumps in /mnt/backup, this also keeps a backup of 
+# (*) /etc/ and in particular /etc/planetlab + all other crontabs and backup-helper
+# (*) /var/www/html for the drupal themes and other stuff
+# (*) /root with various tweaks in particular in /root/thierry
+# in general this is not intended to be restored as-is (as it might overwrite too much stuff)
+# but can be helpful so, just in case ...
+
+# baris: create archive files in /mnt/backup for /etc /var/www/html and /root respectively and sync only /mnt/backup
+# bicudo: added 'cd /' to stop with crontab huge mails
+for d in etc var/www/html root
+do
+  cd /
+  dir_name=`echo ${d} | sed 's/\//_/g'`_
+  tar cjf /mnt/backup/${HOST}_${dir_name}${DATE}.tar.bz2 $d
+done
+
+# baris: copy all files from today to the "latest" directory.
+BACKUP=/mnt/backup
+LATESTDATE=`date +%Y%m%d`
+LATEST=/mnt/backup/latest
+TMP=${LATEST}.temp
+mkdir -p ${TMP} && cp -r $BACKUP/*${LATESTDATE}*.bak $TMP && rm -rf $LATEST && mv $TMP $LATEST
+
+for d in etc var/www/html root
+do
+  mkdir -p $LATEST/$d
+  rsync --archive --verbose --relative --delete  /$d/ $LATEST/$d/
+done
+
+rsync --archive --verbose --relative --delete  /mnt/backup/  --exclude '*~' root@gorillaz:/backup-ple-www
diff --git a/scripts/backup-helper b/scripts/backup-helper
new file mode 100755 (executable)
index 0000000..3468906
--- /dev/null
@@ -0,0 +1,257 @@
+#!/bin/sh
+
+# Goal: backup a directory
+# $1: Destination
+# $2: Server name (i.e.: onelab2)
+# $3: Backup name (i.e.: twiki)
+# $4: Date
+# $5: Directory to backup
+function backup_dir {
+       DEST=$1
+       BACKUP_NAME=$1/$2-$3-$4.tar.bz2
+       DIR=$5
+       mkdir -p $DEST
+       if [ ! -d $DIR ]; then
+               echo " (No such directory) [KO]"
+               return 1
+       fi
+       cd $DIR
+       echo -n "Backup directory $DIR..."
+       tar cfjp $BACKUP_NAME *
+       RES=$?
+       echo -n " (`stat --printf="%s" $BACKUP_NAME`)"
+       if [ $RES -eq 0 ]; then
+               echo " [ OK ]"
+       else
+               echo " [ KO ]"
+       fi
+
+       return 0
+}
+
+# Goal: backup a PostgreSQL database
+# $1: Destination
+# $2: Server name (i.e.: onelab2)
+# $3: Date
+# $4: Database name
+# $5: Database owner
+function backup_db {
+       DEST=$1
+       DBNAME=$4
+       DBUSER=$5
+       BACKUP_NAME=$DEST/$2-db-$DBNAME-$3.bak
+       mkdir -p $DEST
+       echo -n "Backup database $DBNAME..."
+       pg_dump -i -U postgres --user=$DBUSER -F c -f $BACKUP_NAME $DBNAME
+       RES=$?
+       echo -n " (`stat --printf="%s" $BACKUP_NAME`)"
+       if [ $RES -eq 0 ]; then
+               echo " [ OK ]"
+       else
+               echo " [ KO ]"
+               return 1
+       fi
+
+       return 0
+}
+
+# Goal: backup all PostgreSQL databases on the machine
+# $1: Destination
+# $2: Server name (i.e.: onelab2)
+# $3: Date
+function backup_all_dbs {
+       for i in `psql -qtAF '|' -U postgres -l`; do
+               DBNAME=`echo $i | cut -d '|' -f 1`
+               DBUSER=`echo $i | cut -d '|' -f 2`
+               if [ $DBNAME != template0 -a $DBNAME != template1 ]; then
+                       backup_db $1 $2 $3 $DBNAME $DBUSER
+               fi
+       done
+}
+
+# Goal: backup a database in a VServer
+# $1: Destination
+# $2: VServer name (i.e.: onelab2)
+# $3: Backup name (i.e.: twiki)
+# $4: Date
+# $5: Database name
+# $6: Database owner
+function backup_vserver_db {
+       DEST=$1
+       VSERVER=$2
+       BACKUP_NAME=$1/$2-$3-$4.bak
+       DBNAME=$5
+       DBUSER=$6
+       mkdir -p $DEST
+       mkdir -p /vservers/$VSERVER/$DEST
+       echo -n "Backup database $DBNAME..."
+       vserver $VSERVER exec \
+               pg_dump -i -U postgres --user=$DBUSER -F c -v -f $BACKUP_NAME \
+               -- $DBNAME >/dev/null
+       RES=$?
+       mv /vservers/$VSERVER/$BACKUP_NAME $BACKUP_NAME
+       echo -n " (`stat --printf="%s" $BACKUP_NAME`)"
+       if [ $RES -eq 0 ]; then
+               echo " [ OK ]"
+       else
+               echo " [ KO ]"
+               return 1
+       fi
+
+       return 0
+}
+
+# Goal: backup an offline vserver instance
+# $1: Destination (where to save the backup)
+# $2: VServer name (i.e.: plc)
+# $3: Date
+function backup_vserver_offline {
+       DEST=$1
+       VSERVER=$2
+       BACKUP_NAME=$1/$2-vs-$3.off.tar.bz2
+       BACKUP_CONF_NAME=$1/$2-vsconf-$3.off.tar.bz2
+       mkdir -p $DEST
+       echo -n "Backup vserver $VSERVER..."
+       if [ ! -d /etc/vservers/$VSERVER ]; then
+               echo " (No such vserver) [ KO ]"
+               return 1
+       fi
+
+       cd /etc/vservers/$VSERVER &&
+       tar cfjp $BACKUP_CONF_NAME * 2>&1 >/dev/null &&
+       cd /vserver/$VSERVER &&
+       tar cfjp $BACKUP_NAME * 2>&1 >/dev/null
+       RES=$?
+
+       echo -n " (`stat --printf="%s" $BACKUP_NAME`)"
+       if [ $RES -eq 0 ]; then
+               echo " [ OK ]"
+       else
+               echo " [ KO ]"
+               return 1
+       fi
+
+       return 0
+}
+
+# Goal: backup an online vserver instance
+# $1: Destination (where to save the backup)
+# $2: VServer name (i.e.: plc)
+# $3: Date
+# $4: LVM dev on which the VServer is mounted (default to /dev/vg/$2 if empty)
+function backup_vserver_online {
+       DEST=$1
+       VSERVER=$2
+       BACKUP_NAME=$1/$2-vs-$3.on.tar.bz2
+       BACKUP_CONF_NAME=$1/$2-vsconf-$3.on.tar.bz2
+       DEV=$4
+       if [ -z $DEV ]; then
+               DEV="/dev/vg/$VSERVER"
+       fi
+
+       echo -n "Backup vserver $VSERVER..."
+       mkdir -p $DEST >/dev/null
+       
+        SNAPDEV=${DEV}bkp
+        if [ ! -d /etc/vservers/$VSERVER ]; then
+               echo " (No such vserver) [ KO ]"
+                return 1
+        fi
+
+       # Create a snapshot of the running vserver filesystem...
+        SNAPVG=`echo $SNAPDEV | cut -f 3 -d '/'`
+        SNAPLV=`echo $SNAPDEV | cut -f 4 -d '/'`
+        SNAPMOUNT=/tmp/$SNAPLV
+        lvcreate -L20G -s -n$SNAPLV $DEV >/dev/null
+       if [ $? -ne 0 ]; then
+               echo " (Can't create snapshot volume: $SNAPDEV) [ KO ]"
+               return 1
+       fi
+
+        # ... mount it and backup it...
+       cd /etc/vservers/$VSERVER &&
+       tar cfjp $BACKUP_CONF_NAME * &&
+        mkdir -p $SNAPMOUNT &&
+        mount -t ext3 $SNAPDEV $SNAPMOUNT -o ro &&
+        cd $SNAPMOUNT &&
+        tar cfjp $BACKUP_NAME * 2>/dev/null >/dev/null
+       RES=$?
+
+       # ... and remove the snapshot
+       cd &&
+        umount $SNAPMOUNT &&
+        lvremove -f $SNAPDEV >/dev/null &&
+        rmdir $SNAPMOUNT
+       if [ $? -ne 0 ]; then
+               echo " (Can't delete snapshot volume: $SNAPDEV) [ KO ]"
+               return 1
+       fi
+
+       echo -n " (`stat --printf="%s" $BACKUP_NAME`)"
+       if [ $RES -eq 0 ]; then
+               echo " [ OK ]"
+       else
+               echo " [ KO ]"
+               return 1
+       fi
+
+       return 0
+}
+
+# Goal: backup a vserver instance (online or offline)
+# $1: Destination (where to save the backup)
+# $2: VServer name (i.e.: onelab2)
+# $3: Date
+function backup_vserver {
+       DEST=$1
+       VSERVER=$2
+       DATE=$3
+       if [ ! -d /etc/vservers/$VSERVER ]; then
+               echo "Backup vserver $VSERVER... (No such vserver) [ KO ]"
+       fi
+
+       ctx=`cat /etc/vservers/$VSERVER/context`
+       vserver-stat | grep $ctx 2>&1 > /dev/null
+        offline=$?
+
+        if [ $offline -eq 0 ]; then
+                backup_vserver_online $DEST $VSERVER $DATE
+        else
+                backup_vserver_offline $DEST $VSERVER $DATE
+        fi
+        return $?
+}
+
+# Goal: backup all vserver instances (online or offline) on the machine
+# $1: Destination (where to save the backup)
+# $2: Date
+function backup_all_vservers {
+       for i in /etc/vservers/*; do
+               VSERVER=`basename $i`
+               backup_vserver $1 $VSERVER $2
+       done
+}
+
+# Fetch all backups from a server
+# $1: destination
+# $2: hostname
+# $3: backup user
+# $4: backup location
+function fetch_backup {
+       DEST=$1
+       BACKUP_HOST=$2
+       BACKUP_USER=$3
+       BACKUP_LOC=$4
+       echo -n "Fetch backups from $BACKUP_HOST..."
+       su $BACKUP_USER -c "mkdir -pv $DEST"
+       su $BACKUP_USER -c "rsync --exclude="lost+found" -a $BACKUP_USER@$BACKUP_HOST:$BACKUP_LOC/ $DEST"
+       RES=$?
+       if [ $RES -eq 0 ]; then
+               echo " [OK]"
+       else
+               echo " [KO]"
+       fi
+       
+       return 0
+}
+
index 4593317..fe559c9 100755 (executable)
@@ -39,6 +39,20 @@ function fill_descriptions () {
     echo ""
 }
 
+function update_server_info () {
+    echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx updating server info "
+    for arg in "$@" ; do
+       # accept args like plcapi or plcapi.git
+       b=$(basename $arg .git)
+       git=${b}.git
+       echo -n "$git "
+        cd $git
+        git update-server-info
+        cd - >& /dev/null
+    done
+    echo ""
+}
+
 function check_permissions () {
     echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx checking permissions "
     for arg in "$@" ; do
@@ -89,6 +103,7 @@ function check_hooks () {
 args="$@"
 [[ -z "$args" ]] && args=$(ls -d *.git)
 fill_descriptions $args
+update_server_info $args
 check_permissions $args
 check_configs $args
 check_hooks $args