Linux backup

    One day I needed a backup script. Considered a large number of different options. Many are not satisfied because of the bulkiness. As a result, I wrote my script :)

    To backup sites on a web server is very useful and simple :) Suggestions for improvement are welcome. Now we add the task to the crowns and execute it daily, for example, at 3 a.m.



    #!/bin/bash
    PATH_TO_ADIR="/var/www" # бэкапим все в этом каталоге
    PATH_TO_BDIR="/var/backup" #сюда складываем бэкап
    BACKDAYS="5" #сколько дней храним бэкапы

    # создаем директорию, если такой не существует
    if [ ! -d "$PATH_TO_BDIR/$(date +%Y-%m-%d)" ]; then
    mkdir $PATH_TO_BDIR/$(date +%Y-%m-%d)
    fi

    # тут мы бэкапим данные
    for file in $( /bin/ls $PATH_TO_ADIR);
    do
    /usr/bin/nice -n 5 tar zcfP $PATH_TO_BDIR/$(date +%Y-%m-%d)/$file-SITE-$(date +%Y-%m-%d).tgz $PATH_TO_ADIR/$file
    done

    DATM=`/bin/date -d '-'$BACKDAYS' day' +%Y%m%d`
    NOW=`/bin/date +%Y%m%d`
    DATH=`/bin/date --date="$i" +%Y%m%d`

    # а тут мы удаляем старые бэкапы
    for i in `ls $PATH_TO_BDIR/ | awk '{print $1}'`
    do
    if [ $DATH -le $DATM ];then
    /bin/rm -Rf $PATH_TO_BDIR/$i
    fi
    done



    Also popular now: