• [^] # Re: Backup-manager

    Posté par . En réponse au message Script de sauvegarde totale/incrémentielle via tar. Évalué à 2.

    Je viens de finir mon script (manque juste le nettoyage des trop anciennes sauvegardes). Voici mon code (pour qui ca interesse) :


    #!/bin/sh

    date_current=`date "+%Y_%m_%d"`
    dir_synchro='/home/synchro'
    dir_backup='/home/backup'

    function _full(){
    tar -c --atime-preserve -f "$dir_backup/$cat/$scat/$date_current-full.tar.gz" --gzip "$dir_synchro/$cat/$scat" -g "$dir_backup/$cat/$scat/index"
    }
    function _incremental(){
    tar -c --atime-preserve -f "$dir_backup/$cat/$scat/$date_current-incremental.tar.gz" --gzip "$dir_synchro/$cat/$scat" -g "$dir_backup/$cat/$scat/index"
    }
    function _added(){
    tar -c --atime-preserve -f "$dir_backup/$cat/$scat/$date_current-full-added.tar.gz" --gzip "$dir_synchro/$cat/$scat"
    }

    for cat in `ls "$dir_synchro" | tr -s ' ' '!'`
    do
    cat=`echo "$cat" | tr -s '!' ' '`
    for scat in `ls "$dir_synchro/$cat" | tr -s ' ' '!'`
    do
    scat=`echo "$scat" | tr -s '!' ' '`
    mkdir "$dir_backup/$cat/$scat" -p
    if [ `ls "$dir_backup/$cat/$scat/" | grep '.tar.gz' | grep -v 'added' | grep "full\|incremental" | wc -l` -eq 0 ]
    then
    _full
    else
    if [ ! -e "$dir_backup/$cat/$scat/$date_current-full.tar.gz" ] && [ ! -e "$dir_backup/$cat/$scat/$date_current-incremental.tar.gz" ]
    then
    if [ `date "+%w"` -eq 1 ]
    then
    _full
    else
    _incremental
    fi
    else
    if [ -e "$dir_backup/$cat/$scat/$date_current-full.tar.gz" ] && [ ! -e "$dir_backup/$cat/$scat/$date_current-incremental.tar.gz" ]
    then
    _incremental
    else
    _added
    fi
    fi
    fi
    done
    done