From 2394edf7da7d649ed6f62603db01433842015d68 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 19 Apr 2017 11:28:55 +0400 Subject: [PATCH] =?UTF-8?q?toinst:=20impl=C3=A9menter=20la=20sauvegarde?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- toinst | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/toinst b/toinst index c484f66..1d29760 100755 --- a/toinst +++ b/toinst @@ -494,11 +494,59 @@ fi ## Sauvegarde if [ -n "$BACKUP" -o "$action" == backup ]; then - if [ -n "$fake" ]; then - : + [ -n "$CATALINA_BASE" -o -z "$will_deploy" ] || die "Vous devez spécifier l'option --catalina-base" + + home_bckdir="$HOME/tomcat-backups" + if [ -n "$istmpdir" ]; then + # déploiement distant: sauvegarder dans le répertoire utilisateur + default_bckdir="$home_bckdir" else - : + # déploiement local: ça dépend de la webapp + default_bckdir= fi + setx cwd=pwd + + etitle "Sauvegarde des webapps" + for deploymap in "${deploymaps[@]}"; do + splitpair "$deploymap" waname src + wadir="$CATALINA_BASE/webapps/$waname" + + if [ ! -d "$wadir" ]; then + einfo "$waname: la webapp n'a pas encore été déployée. elle ne sera pas sauvegardée" + continue + fi + + bckdir="$default_bckdir" + if [ -z "$bckdir" ]; then + if withinpath "$tmpdir" "$src"; then + bckdir="$home_bckdir" + elif withinpath "$src" "$cwd"; then + setx bckdir=dirname "$src" + else + bckdir=. + fi + fi + mkdir -p "$bckdir" + + setx base=date +%y%m%d + i=0 + bckname="$base.$profile$i-$waname" + while [ -d "$bckdir/$bckname" ]; do + let i=$i+1 + bckname="$base.$profile$i-$waname" + done + + if [ -n "$fake" ]; then + evalx qvals rsync -a "$wadir/" "$bckdir/$bckname" // eecho + else + estep "$wadir --> $(ppath "$bckdir/$bckname")" + if ! rsync -a "$wadir/" "$bckdir/$bckname"; then + ewarn "Une erreur s'est produite pendant la sauvegarde" + ask_yesno "Voulez-vous continuer le déploiement?" N || die + fi + fi + done + eend fi ## Déploiement @@ -507,7 +555,7 @@ if [ "$action" == deploy ]; then if [ -n "$fake" ]; then # Afficher ce qu'il faut faire - etitle "Variables définies" __dump_vars + etitle "Configuration globale" __dump_vars etitle "Déploiements des webapps" for deploymap in "${deploymaps[@]}"; do splitpair "$deploymap" waname src @@ -515,7 +563,7 @@ if [ "$action" == deploy ]; then dest="${CATALINA_BASE:-CATALINA_BASE}/webapps/$waname" etitle "$waname" if [ -f "$src/.toinst.conf" ]; then - etitle "Variables locales" + etitle "Configuration de la webapp" ( EXCLUDES=() PROTECTS=()