Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script de backup des fichiers session rtorrent.
#!/usr/bin/env bash
#
# Nom du script .. : backup-rtorrent.sh
# Version ........ : 1.30
# Date ........... : 29/03/2015
# Auteur ......... : magicalex
#
# Description : script de backup des données rtorrent.
#
# Installation :
# crontab -e (du user rtorrent)
# "0 5 * * * /home/<username>/script/backup-rtorrent.sh > /dev/null 2>&1"
#
# nombre de sauvegarde souhaité 7 par defaut
NBSAVE=7
# Date de sauvegarde
DATE=$(date "+%d-%m-%y-a-%Hh%Mm%Ss")
# fonction backup
function backup() {
REPERTOIREUSER="/home/$1/backup"
if [ ! -d "$REPERTOIREUSER" ]
then
mkdir "/home/$1/backup"
chown -R "$1:$1" "/home/$1/backup"
fi
mkdir "/home/$1/backup/Sauvegarde-du-$DATE"
cp "/home/$1/.session/*.torrent" "/home/$1/.session/*.rtorrent" "/home/$1/.session/*.libtorrent_resume" "/home/$1/backup/Sauvegarde-du-*"
cd "/home/$1/backup/"
zip -qr "sauvegarde-du-$DATE.zip Sauvegarde-du-*"
rm -Rf "/home/$1/backup/Sauvegarde-du-*"
chown -R "$1:$1" "/home/$1/backup/"
COMPTAGE=$(ls | grep "sauvegarde" | wc -l)
if [ $COMPTAGE -gt $NBSAVE ]
then
rm -Rf $(ls -at "/home/$1/backup/" | grep "sauvegarde" | tail -1)
fi
}
backup $USER
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.