46 lines
976 B
Bash
46 lines
976 B
Bash
#!/bin/bash
|
|
# TODO
|
|
# home (hors données distribuées)
|
|
# repos git
|
|
# crypter les données secu
|
|
# copier vers ftp
|
|
|
|
# repertoire contenant les backups
|
|
BACKUP_DIR=/home/backup
|
|
BACKUP_CUR=$BACKUP_DIR/current
|
|
mkdir -p $BACKUP_CUR
|
|
|
|
function do_backup {
|
|
BACKUP_PATH=$1
|
|
BACKUP_NAME=$2
|
|
|
|
BACKUP_FILE=$BACKUP_DIR/$BACKUP_NAME.$(date +%Y%m%d).tar.gz
|
|
BACKUP_LST=$BACKUP_DIR/$BACKUP_NAME.lst
|
|
ARCHIVE_DIR=$BACKUP_DIR/$(date +%Y%m%d)
|
|
# si le lst existe, incremental
|
|
test -f $BACKUP_LST
|
|
INCR_BACKUP=$?
|
|
|
|
tar cpzf $BACKUP_FILE -C / --listed-incremental=$BACKUP_LST $BACKUP_PATH
|
|
# TODO crypt
|
|
|
|
# si non incremental (cad complet) copie vers repertoire archive
|
|
if [ $INCR_BACKUP -ne 0 ]
|
|
then
|
|
mkdir -p $ARCHIVE_DIR
|
|
mv $BACKUP_FILE $ARCHIVE_DIR
|
|
# effacer les backups incrementaux précédents
|
|
rm -rf $BACKUP_CUR
|
|
else
|
|
mv $BACKUP_FILE $BACKUP_CUR
|
|
fi
|
|
}
|
|
|
|
# /etc
|
|
do_backup "/etc/" "$(hostname).etc"
|
|
|
|
# webapps
|
|
# TODO pas besoin d'etre root
|
|
do_backup "/home/www" "$(hostname).www"
|
|
|