• [^] # Re: Cryptage ou protection de données avant sauvegarde?

    Posté par (site web personnel) . En réponse au message Cryptage ou protection de données avant sauvegarde?. Évalué à 1.

    Voila mes scripts, pour référence:
    (le fichier crypt_backup.conf permettait de définir les variables)

    En fait, c'etait assez poussé parceque ca permettais de sauver sur ISO ou bien sur bande, et ca utilisait Tar+gzip pour la compression, GPG pour la crypto et PAR pour l'archivage (PAR permet de sauvegarder des infos redondantes pour supporter la perte d'un segment de données, par exemple si l'une des bandes s'averais foutue)
    C'était pour des grosses archives (10-20Go) sur des bandes de 2Go.

    Je me rapelle que la crypto via GPG était horriblement lente (plusieurs dizaines d'heures), surtout a cause de l'utilisation de crypto asymmétrique.

    Bref, ca a très bien marché jusqu'au jour ou j'ai paumé le fichier de clé privé, et la je me suis retrouvé avec 200 K7 inutilisable.
    => A bon entendeur...

    ***************************
    **** crypt_backup.sh ***
    ***************************

    #!/bin/bash
    source ~/.crypt_backup.conf
    # Renice myself (and so all the childs) to avoid hitting the machine when in a backup
    renice +20 $$
    if [ "$tape_host" ] ; then
    if [ "$tape_user" ] ; then
    tape_device=$tape_user@
    fi
    tape_device=$tape_device$tape_host%ssh:$tape_file
    else
    tape_device=$tape_file
    fi
    ### Functions ###
    function backup_to_tape {
    ls $* | afio -o -b $tape_bloc -z $tape_device
    if [ $tape_host ] ; then
    ssh $tape_user@$tape_host mt -f $tape_file eject
    else
    mt -f $tape_file eject
    fi
    }
    ### End of functions ####
    ### Main ###
    if [ -z 1ドル ] ;then
    echo "Usage : 0ドル <archive name> [] ..."
    exit
    fi
    target=1ドル
    shift
    for d in $* ; do
    if [ ! -r $d ] ; then
    echo "Error, target $d unreadable"
    exit
    fi
    targets="$targets $d"
    done
    if [ -z $targets ] ; then
    echo "Error : nothing to backup"
    exit
    fi
    echo "Device = $tape_device"
    echo -n "Backup to tape or iso ? (t or i) : "
    read media
    if [ $media != "t" -a $media != "i" ] ; then
    echo "Error, reply by t or i"
    exit
    fi
    real_tmp_dir=`mktemp -d -p $tmp_dir`
    tar -cvf - $targets | gpg -e -r $gpg_fingerprint | split -b $tape_size -d - "$real_tmp_dir/$target.gpg."
    cd $real_tmp_dir/
    count=`ls $target.gpg.[0-9][0-9] | wc -l`
    echo "Number of volume : $count"
    par2 c -n$count -u $target.gpg.[0-9][0-9]
    par_targets=(`ls $target.gpg.??.vol*.par2`)
    count=0
    if [ $media = "t" ] ; then
    # Then backup files, one per tape
    for f in $target.gpg.[0-9][0-9] ; do
    if [ $count != 0 ] ; then
    echo "Insert next tape...."
    read
    fi
    backup_to_tape $f ${par_targets[$count]}
    let count+=1
    done
    fi
    if [ $media = "i" ] ; then
    for f in $target.gpg.[0-9][0-9] ; do
    mkisofs -o $iso_dir/$f.iso -R -l ./$f ./${par_targets[$count]}
    let count+=1
    done
    fi
    echo -n "Remove temporary directory ? (Y/n) : "
    read r
    if [ $r != "n" -a $r != "N" ] ; then
    rm -rd $real_tmp_dir
    fi


    ************************
    *** crypt_restore.sh ***
    ************************

    #!/bin/bash
    source ~/.crypt_backup.conf
    ### Functions ###
    function copy_files_from_tape {
    afio -iz $tape_device
    mt -f $tape_device rewind
    mt -f $tape_device eject
    }
    function copy_files_from_cd {
    mount $mnt_dir
    cp -a $mnt_dir/* .
    eject $mnt_dir
    }
    ### Main ###
    echo -n "Restore from tape or directory ? (t or d) : "
    read media
    if [ $media != "t" -a $media != "d" ] ; then
    echo "Error, reply by t or d"
    exit
    fi
    real_tmp_dir=`mktemp -d -p $tmp_dir`
    cd $real_tmp_dir
    echo -n "Insert PAR-files media and press enter"
    read
    if [ $media = "t" ] ; then
    copy_files_from_tape
    elif [ $media = "m" ] ; then
    copy_files_from_cd
    fi
    e=""
    while [ "$e" != "q" ] ; do
    echo -n "Insert next data media and press enter when ready, or q to exit"
    read e
    if [ $e != "q" ] ; then
    if [ $media = "t" ] ; then
    copy_files_from_tape
    elif [ $media = "m" ] ; then
    copy_files_from_cd
    fi
    fi
    done
    # Repair archive if necessary (and possible)
    par2 r *.par2
    echo -n "Please verify that the archive is not corrupted and press enter...."
    read
    archive=`basename *.gpg.00 .00`
    count=`ls $archive.[0-9][0-9] | wc -l`
    if [ $count = 0 ] ; then
    echo "Error : Cannot find archive $archive."
    exit
    else
    for f in $archive.[0-9][0-9] ; do
    cat $f >> $archive
    done
    fi
    # return in cwd to untar
    cd -
    gpg < $real_tmp_dir/$archive | tar -xvf -
    echo -n "Remove temporary directory ? (Y/n) : "
    read r
    if [ $r != "n" -a $r != "N" ] ; then
    rm -rd $real_tmp_dir
    fi