summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cnf/fsave.conf22
-rw-r--r--src/ejabberd.sh44
-rw-r--r--src/files.sh10
-rwxr-xr-x[-rw-r--r--]src/fsave.sh66
-rw-r--r--src/gest-screen.sh14
-rw-r--r--src/gest-url.sh28
-rw-r--r--src/iptables.sh36
-rw-r--r--src/ldap.sh37
-rw-r--r--src/mysql.sh40
-rw-r--r--src/typo.sh41
10 files changed, 279 insertions, 59 deletions
diff --git a/cnf/fsave.conf b/cnf/fsave.conf
index daab5e8..381404c 100644
--- a/cnf/fsave.conf
+++ b/cnf/fsave.conf
@@ -1,7 +1,7 @@
# /etc/fsave.conf
# Fichier de configuration de fsave
#
-# (c) 2005-2006 Bertand Jacquin <beber_AT_meleeweb.net>
+# (c) 2005-2007 Bertand Jacquin <beber@meleeweb.net>
# Under GPL-2
# PATH_TO_SAVE:
@@ -19,27 +19,23 @@
# mysql://127.0.0.1 mysql://root:motdepasse@sbdg.domain.com/phpbb \
# mysql://john@localhost"
#
-PATH_TO_SAVE=" /etc /var/chroot /var/www/ /usr/local \
- /home/beber/cic.gsb /home/beber/.enlightenment \
- /home/beber/bin /root/bin \
- mysql://beber@localhost"
-
-#PATH_TO_SAVE=" /etv \
-# /dev \
-# mysql://root:@localhost/sys_cacti \
-# ssh://zesdfx"
+#PATH_TO_SAVE="typo:///var/www/else-projects.org/htdocs/typo"
# DEST:
# Destination des sauvegardes (peut etre un montage ou autre)
# Préférer une partition prévue a cet effet
#
-DEST="/mnt/save"
+DEST="/data/backup"
# TO_UMOUNT:
# La partition de sauvegarde doit-elle etre démontée a la fin de la procédure ?
# Peut etre O ou 1
-TO_UMOUNT=0
+TO_UMOUNT=1
+
+# EMAILTO:
+# Definie le destinataire des sauvegardes
+EMAILTO="beber.arch@gmail.com"
# MODULES:
# Modules a charger
-MODULES="mysql"
+MODULES="mysql ejabberd typo iptables ldap"
diff --git a/src/ejabberd.sh b/src/ejabberd.sh
new file mode 100644
index 0000000..0df3022
--- /dev/null
+++ b/src/ejabberd.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+#
+# (c) 2005-2007 Bertrand Jacquin <beber@meleeweb.net>
+# Under GPL-2
+#
+# Module ejabberd pour fsave
+
+REGISTER_PROTO="$REGISTER_PROTO ejabberd:ejabberd_archive"
+
+ejabberd_archive()
+{
+ local node="${FUSER}@${FHOST}"
+
+ moreindent
+ local FDEST="${DEST}/ejabberd/${node}"
+ check_fdest
+
+ einfo "ejabberd: Dumping ejabberd database (node: ${node})"
+ local cmd="ejabberdctl ${node} dump ${FDEST}/${DATE}.db.txt"
+ moreindent
+ eecho "${cmd}"
+ ${cmd}
+
+ lessindent
+
+ einfo "ejabberd: Backup ejabberd database (node: ${node})"
+ local cmd="ejabberdctl ${node} backup ${FDEST}/${DATE}.db"
+ moreindent
+ eecho "${cmd}"
+ ${cmd}
+
+ einfo "ejabberd: Compressing backup"
+ local cmd="tar cjf ${FDEST}/${DATE}.tar.bz2 ${FDEST}/${DATE}.db*"
+ eecho "${cmd}"
+ ${cmd}
+
+ rm ${FDEST}/${DATE}.db*
+
+ lessindent
+
+ export LAST_ARCH=${FDEST}/${DATE}.tar.bz2
+
+ lessindent
+}
diff --git a/src/files.sh b/src/files.sh
index 798ff98..5fb78ec 100644
--- a/src/files.sh
+++ b/src/files.sh
@@ -1,6 +1,6 @@
-#!/bin/sh
+#!/bin/bash
#
-# (c) 2005-2006 Bertand Jacquin <beber_AT_meleeweb.net>
+# (c) 2005-2007 Bertand Jacquin <beber@meleeweb.net>
# Under GPL-2
#
# Modules de sauvegarde de repertoire et fichier pour fsave
@@ -26,8 +26,10 @@ files_archive()
check_fdest
einfo "Taring $1 to ${FDEST}/${DATE}.tar.bz2"
- eecho "tar -cj --atime-preserve --preserve-permissions --index-file ${FDEST}/${DATE}.log -f ${FDEST}/${DATE}.tar.bz2 $1"
- tar -cj --atime-preserve --preserve-permissions --index-file ${FDEST}/${DATE}.log -f ${FDEST}/${DATE}.tar.bz2 $1 2>&1 >> ${FDEST}/${DATE}.log
+ eecho "tar -cj --atime-preserve --preserve-permissions -f ${FDEST}/${DATE}.tar.bz2 $1"
+ tar -cj --atime-preserve --preserve-permissions -f ${FDEST}/${DATE}.tar.bz2 $1 2>&1
+
+ export LAST_ARCH="${FDEST}/${DATE}.tar.bz2"
lessindent
lessindent
diff --git a/src/fsave.sh b/src/fsave.sh
index d879266..9f71f74 100644..100755
--- a/src/fsave.sh
+++ b/src/fsave.sh
@@ -1,30 +1,41 @@
#!/bin/sh
-# (c) Beber 2005-2006 <beber_AT_meleeweb.net>
+# (c) Beber 2005-2007 <beber@meleeweb.net>
# Under GPL-2
-# Sauvegarde de répertoire pour crontab
-# Monte la destination si possible et démontage
+# Sauvegarde de répertoire pour crontab
+# Monte la destination si possible et démontage
# Enregistre au format <destination>/<chemin a sauvegarder>-<date du jour>.tar.bz2
-# Création d'un log
+# Création d'un log
# Todo:
-# Si destination non trouvé alors rechercher le point de montage qui serait le plus adéquate et test de récursivité (si repertoire dans partition, !root de la partition)
-# Gestion des différentes sauvegarde faite
+# Si destination non trouvé alors rechercher le point de montage qui serait le plus adéquate et test de récursivité (si repertoire dans partition, !root de la partition)
+# Gestion des différentes sauvegarde faite
# Gestion du nombre max de sauvegarde | date maxi | temps de stockage max (par options)
-# Calcul de la taille moyenne d'une sauvegarde pour éviter le remplissage de la partition de stockage
+# Calcul de la taille moyenne d'une sauvegarde pour éviter le remplissage de la partition de stockage
# Suppression d'une vieille sauvegarde (par options)
-# Laisser le choix du démontage a la fin (par options)
+# Laisser le choix du démontage a la fin (par options)
# SCP sur machine distante de la sauvegarde
# Script pour la restauration
-# Script pour visualiser/gérer les sauvegarde
-# Vérif de si sauvegarde sur machine distante ok
+# Script pour visualiser/gérer les sauvegarde
+# Vérif de si sauvegarde sur machine distante ok
# Sauvegarde de /dev/x (dd)
# Sauvegarde svn (svnadmin dump / hotcopy)
# Sauvegarde mysql
-# Rajouter la possiblité de sauvegarder une table
-# Modifier le code pour plus de flexibilité dans le traitement des user, pass, host & bases
+# Rajouter la possiblité de sauvegarder une table
+# Modifier le code pour plus de flexibilité dans le traitement des user, pass, host & bases
+renice 19 -p $$ > /dev/null
+umask 077
+
+if [ $# -ne 0 ] ; then
+ if [ "$1" = "-nc" ] ; then
+ COLOR="no"
+ else
+ echo "Unknown option: $1" 2>&1
+ exit 2
+ fi
+fi
. /usr/lib/fsave/gest-screen.sh
. /usr/lib/fsave/gest-url.sh
@@ -36,7 +47,7 @@
check_fsave_conf
-DATE=`date +%F`
+DATE=$(date +%F)
check_to_save
dest_mount
@@ -50,27 +61,32 @@ for i in $PATH_TO_SAVE
do
get_proto $i
- if [ -z $PROTO ]
+ if [ -z ${PROTO} ]
then
files_archive $i
else
+# if [ -d ${i} ] ; then
+# files_archive ${i}
+# break
+# fi
+
cut_url $i
- # Crado, a travailler avec du sed pour récuperer directement la commande a executer
- if [ `echo $REGISTER_PROTO | grep $PROTO | wc -l` -eq 0 ]
+ # Crado, a travailler avec du sed pour récuperer directement la commande a executer
+ if [ $(echo ${REGISTER_PROTO} | grep ${PROTO} | wc -l) -eq 0 ]
then
moreindent
- eerror "$PROTO is not a supported protocol"
+ eerror "${PROTO} is not a supported protocol"
lessindent
else
- for j in $REGISTER_PROTO
+ for j in ${REGISTER_PROTO}
do
- if [ `echo $REGISTER_PROTO | grep $PROTO | wc -l` -eq 1 ]
+ if [ $(echo $j | grep $PROTO | wc -l) -eq 1 ]
then
- FCT_TO_CALL=`echo $j | cut -s -d ':' -f 2`
- if [ -z $FCT_TO_CALL ]
+ FCT_TO_CALL=$(echo $j | cut -s -d ':' -f 2)
+ if [ -z ${FCT_TO_CALL} ]
then
- eerror "Module for $PROTO is not usable"
+ eerror "Module for ${PROTO} is not usable"
else
$FCT_TO_CALL
break
@@ -79,6 +95,12 @@ do
done
fi
fi
+
+ if [ -n "${LAST_ARCH}" ] ; then
+ einfo "Send $LAST_ARCH to $EMAILTO"
+ mpack -s "${DATE}: ${LAST_ARCH}" "${LAST_ARCH}" ${EMAILTO}
+ unset LAST_ARCH
+ fi
done
dest_umount
diff --git a/src/gest-screen.sh b/src/gest-screen.sh
index ef03776..9ec8188 100644
--- a/src/gest-screen.sh
+++ b/src/gest-screen.sh
@@ -7,12 +7,14 @@
DOTS="..."
-GOOD=$'\e[32;01m'
-WARN=$'\e[33;01m'
-BAD=$'\e[31;01m'
-NORMAL=$'\e[0m'
-HILITE=$'\e[36;01m'
-BRACKET=$'\e[34;01m'
+if [ "$COLOR" != "no" ] ; then
+ GOOD=$'\e[32;01m'
+ WARN=$'\e[33;01m'
+ BAD=$'\e[31;01m'
+ NORMAL=$'\e[0m'
+ HILITE=$'\e[36;01m'
+ BRACKET=$'\e[34;01m'
+fi
INDENT=" "
diff --git a/src/gest-url.sh b/src/gest-url.sh
index 45339a6..d2a0469 100644
--- a/src/gest-url.sh
+++ b/src/gest-url.sh
@@ -10,7 +10,13 @@ get_proto()
{
local URL=$1
- PROTO=`echo $URL | cut -s -d ':' -f 1`
+ if [ -d ${URL} -o -f ${URL} ] ; then
+ PROTO=
+ return
+ fi
+
+# PROTO=`echo $URL | cut -s -d ':' -f 1`
+ PROTO=${URL%%:*}
}
# Fonction récuperant le user, mot de passe, host et chemin
@@ -21,15 +27,23 @@ cut_url()
local URL=$1
local FULL_WITHOUT_PROTO=`echo $URL | cut -c $((${#PROTO}+4))-`
- local FUSER_AND_FPASS=`echo $FULL_WITHOUT_PROTO | rev | cut -s -d '@' -f 2- | rev`
- local FHOST_AND_FPATH=`echo $FULL_WITHOUT_PROTO | rev | cut -s -d '@' -f 1 | rev`
+# local FUSER_AND_FPASS=`echo $FULL_WITHOUT_PROTO | rev | cut -s -d '@' -f 2- | rev`
+# local FHOST_AND_FPATH=`echo $FULL_WITHOUT_PROTO | rev | cut -s -d '@' -f 1 | rev`
+ local FUSER_AND_FPASS=${FULL_WITHOUT_PROTO//@*}
+ local FHOST_AND_FPATH=${FULL_WITHOUT_PROTO##*@}
- FUSER=`echo $FUSER_AND_FPASS | cut -s -d ':' -f 1`
- FPASS=`echo $FUSER_AND_FPASS | cut -s -d ':' -f 2-`
+# FUSER=`echo $FUSER_AND_FPASS | cut -s -d ':' -f 1`
+# FPASS=`echo $FUSER_AND_FPASS | cut -s -d ':' -f 2-`
+ FUSER=${FUSER_AND_FPASS/:*}
+ FPASS=${FUSER_AND_FPASS#*:}
- FHOST=`echo $FHOST_AND_FPATH | cut -s -d '/' -f 1`
- FPATH=`echo $FHOST_AND_FPATH | cut -s -d '/' -f 2-`
+# FHOST=`echo $FHOST_AND_FPATH | cut -s -d '/' -f 1`
+# FPATH=`echo $FHOST_AND_FPATH | cut -s -d '/' -f 2-`
+ FHOST=${FHOST_AND_FPATH//\/*}
+ FPATH=${FHOST_AND_FPATH##*/}
FUSER=${FUSER:-"$USER"}
FHOST=${FHOST:-"localhost"}
+
+ export FUSER FPASS FHOST FPATH
}
diff --git a/src/iptables.sh b/src/iptables.sh
new file mode 100644
index 0000000..72d9ec0
--- /dev/null
+++ b/src/iptables.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# (c) 2005-2006 Bertrand Jacquin <beber@meleeweb.net>
+# Under GPL-2
+#
+# Module MySQL pour fsave
+
+REGISTER_PROTO="$REGISTER_PROTO iptables:iptables_archive"
+
+iptables_archive()
+{
+ moreindent
+ einfo "iptables: Dumping state"
+
+ local FDEST="${DEST}/iptables"
+ check_fdest
+
+ moreindent
+
+ cmd="iptables-save -c"
+ eecho "${cmd}"
+ ${cmd} > ${FDEST}/${DATE}.ipt
+
+ lessindent
+
+ cmd="tar cjf ${FDEST}/${DATE}.tar.bz2 ${FDEST}/${DATE}.ipt"
+ eecho "${cmd}"
+ ${cmd}
+
+ eecho "rm -r ${FDEST}/${DATE}.ipt"
+ rm -r ${FDEST}/${DATE}.ipt
+
+ export LAST_ARCH=${FDEST}/${DATE}.tar.bz2
+
+ lessindent
+}
diff --git a/src/ldap.sh b/src/ldap.sh
new file mode 100644
index 0000000..00452fe
--- /dev/null
+++ b/src/ldap.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# (c) 2005-2007 Bertrand Jacquin <beber@meleeweb.net>
+# Under GPL-2
+#
+# Module MySQL pour fsave
+
+REGISTER_PROTO="$REGISTER_PROTO ldap:ldap_archive"
+
+ldap_archive()
+{
+ basedn=${FHOST#*,}
+ FHOST=${FHOST%%,*}
+
+ moreindent
+ einfo "OpenLDAP: Dumping ${basedn} tree"
+
+ local FDEST="${DEST}/ldap/${basedn}"
+ check_fdest
+
+ replace_password_with_star
+
+ ecmd="ldapsearch -LLL -x -y /etc/ldap.secret -D ${FUSER} -b ${basedn} -h ${FHOST}"
+ eecho "${ecmd}"
+ ${ecmd} > ${FDEST}/${DATE}.ldif
+
+ ecmd="tar cjf ${FDEST}/${DATE}.tar.bz2 ${FDEST}/${DATE}.ldif"
+ eecho "${ecmd}"
+ ${ecmd}
+
+ eecho "rm ${FDEST}/${DATE}.ldif"
+ rm -r ${FDEST}/${DATE}.ldif
+
+ export LAST_ARCH=${FDEST}/${DATE}.tar.bz2
+
+ lessindent
+}
diff --git a/src/mysql.sh b/src/mysql.sh
index f4fb83c..539172e 100644
--- a/src/mysql.sh
+++ b/src/mysql.sh
@@ -17,18 +17,44 @@ mysql_archive()
local JUST_BASE=$SQL_BASE
SQL_BASE=${SQL_BASE:+"--databases $SQL_BASE"}
- SQL_BASE=${SQL_BASE:-"--all-databases"}
+ SQL_BASE=${SQL_ASE:-"--all-databases"} # Volontaire !
- local FDEST="${DEST}/mysql/${FHOST}/${JUST_BASE:-"all-databases"}"
+ local FDEST="${DEST}/mysql/${JUST_BAS:-"all-databases"}" # Volontaire !
check_fdest
replace_password_with_star
-
+
moreindent
- eecho "mysqldump $SQL_BASE --comments --lock-tables --host=$FHOST --user=$FUSER ${FPASS:+"--password=$STAR_PASS"} | gzip > ${FDEST}/${DATE}.gz"
-
- mysqldump $SQL_BASE --comments --lock-tables --host=$FHOST --user=$FUSER ${FPASS:+"--password=$FPASS"} | gzip > ${FDEST}/${DATE}.gz
+ einfo "Getting all databases"
+ all_db=$(mysql --user=$FUSER ${FPASS:+"--password=$FPASS"} << EOF | tail -n +2
+show databases
+EOF)
+
+ eecho "mkdir -p ${FDEST}/${DATE}"
+ mkdir -p ${FDEST}/${DATE}
+
+ for base in $all_db
+ do
+
+ einfo "Dumping base $base"
+ moreindent
+ eecho "mysqldump ${base} --comments --lock-tables --host=$FHOST --user=$FUSER ${FPASS:+"--password=$STAR_PASS"} > ${FDEST}/${DATE}/${base}.sql"
+
+
+ mysqldump ${base} --comments --lock-tables --host=$FHOST --user=$FUSER ${FPASS:+"--password=$FPASS"} > ${FDEST}/${DATE}/${base}.sql
+ #eecho "mysqlhotcopy --user=$FUSER ${FPASS:+"--password=$STAR_PASS"} ${base} ${FDEST}/${DATE}/${base}/"
+ #mysqlhotcopy --user=$FUSER ${FPASS:+"--password=$FPASS"} ${base} ${FDEST}/${DATE}/${base}/ > /dev/null
+
+ lessindent
+ done
+
+ eecho "tar cjf ${FDEST}/${DATE}.tar.bz2 ${FDEST}/${DATE}"
+ tar cjf ${FDEST}/${DATE}.tar.bz2 ${FDEST}/${DATE} > /dev/null 2>&1
+
+ eecho "rm -r ${FDEST}/${DATE}"
+ rm -r ${FDEST}/${DATE}
+
+ export LAST_ARCH=${FDEST}/${DATE}.tar.bz2
lessindent
- lessindent
}
diff --git a/src/typo.sh b/src/typo.sh
new file mode 100644
index 0000000..bddf168
--- /dev/null
+++ b/src/typo.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# (c) 2005-2007 Bertrand Jacquin <beber_AT_meleeweb.net>
+# Under GPL-2
+#
+# Module typo pour fsave
+
+REGISTER_PROTO="$REGISTER_PROTO typo:typo_archive"
+
+typo_archive()
+{
+ local blog_path="${FUSER}"
+ local site=$(echo ${blog_path} | cut -d '/' -f 4)
+
+ local FDEST="${DEST}/typo/${site}"
+ check_fdest
+
+ einfo "typo: Backup ${blog_path}"
+ local cmd="typo backup ${blog_path}"
+ moreindent
+ eecho "${cmd}"
+ local file_path=$(${cmd} 2>&1 | awk '{print $4}')
+
+ local cmd="mv ${file_path} ${FDEST}/${DATE}.yml"
+ eecho "${cmd}"
+ ${cmd}
+
+ lessindent
+
+ einfo "typo: Compressing backup"
+ moreindent
+ local cmd="tar cjf ${FDEST}/${DATE}.tar.bz2 ${FDEST}/${DATE}.yml"
+ eecho "${cmd}"
+ ${cmd}
+
+ rm ${FDEST}/${DATE}.yml
+
+ export LAST_ARCH="${FDEST}/${DATE}.tar.bz2"
+
+ lessindent
+}