Zola2 // Tout // Rien // Surtout Rien

Disque externe : automatiser une backup distante avec un My Book World Edition

août23

Les disques dur ethernet Western Digital My Book World Edition (version led blanche) ont une version de linux AMR ambarqué. Il est donc possible d’ajouter des petites applications et d’y mettre des crons, donc d’automatiser par exemple une sauvegarde du contenu chaque nuit sur un serveur spécifique…

1ere étape, installer un gestionnaire de package :

Quand vous êtes connecté en ssh (login : admin, mot de passe : Welc0me), voici les commandes à lancer pour installer le gestionnaire :

feed=http://ipkg.nslu2-linux.org/feeds/optware/cs05q1armel/cross/unstable
ipk_name=$(wget -qO- $feed/Packages | awk ‘/^Filename: ipkg-opt/ {print $2}’)
wget $feed/$ipk_name
tar -xOvzf $ipk_name ./data.tar.gz | tar -C / -xzvf –
mkdir -p /opt/etc/ipkg
echo « src armel http://ipkg.nslu2-linux.org/feeds/optware/cs05q1armel/cross/unstable » > /opt/etc/ipkg/armel-feed.conf
wget http://mybookworld.wikidot.com/local–files/optware/sort_dirname.tar.gz
tar xvfz sort_dirname.tar.gz -C /

Installez nano :

/opt/bin/ipkg install nano

Installez lftp :

/opt/bin/ipkg install lftp

Pour lancer une application installée, par exemple nano :

/opt/bin/nano

Créer un script shell pour lancer la backup :

Via nano : /opt/bin/nano /root/backup.sh

/opt/bin/lftp ftp://identifiant:mot_de_passe@site_de_connexion -e « mirror -e -R /emplacement_local /emplacement_distant ; quit »

Ctrl+O pour sauver

Un p’tit coup de chmod +x pour le passer en executable :

chmod +x /root/backup.sh

Ensuite on ajoute la tache dans le cron et le tour est joué !

Mise en place du cron

Créez le fichier /etc/init.d/S99crond

#!/bin/sh

# Script to enable crond (Dillon’s cron) on My Book whitelight (WWLXN-WDH1NC)
#                                                                              
# Since /var/spool links to /tmp the default crontabs location in              
# /var/spool/cron/crontabs will get blown out on reboot. Instead we’ll
# map the crontabs to /etc/crontabs                   
#                                                     
# Put this script in /etc/init.d/S99crond and chmod 755

check_crontabs() {
        if test ! -d /etc/crontabs ; then
                echo « Creating /etc/crontabs »
                mkdir /etc/crontabs
                echo « # crond control file for root (system) » > /etc/crontabs/root
                echo « # Restart crond after editing (/etc/init.d/S99crond restart) » >> /etc/crontabs/root
                echo « # m h dom mon dow   command » >> /etc/crontabs/root
                echo « # Uncomment next line and restart crond to test » >> /etc/crontabs/root
                echo « #* * * * * touch /tmp/crontab.test » >> /etc/crontabs/root
                ln -sf /etc/crontabs/root /etc/crontab
        fi
}

is_running() {
        PID=`ps aux | grep « crond -c \/etc\/crontabs » | grep -v grep | sed ‘s/^ *//’ | cut -f 1 -d ‘ ‘`
        if test -z $PID ; then
                return 0
        else
                return 1
        fi
}

start() {
        check_crontabs
        echo -n « Starting crond: « 
        is_running
        if test $? -eq 0 ; then
                /usr/sbin/crond -c /etc/crontabs
                touch /var/lock/crond
                echo « OK »
        else
                echo « crond is already running »
        fi
}      

stop() {
        echo -n « Stopping crond: « 
        is_running
        if test $? -eq 1 ; then
                killall crond
                rm -f /var/lock/crond
                echo « OK »
        else
                echo « crond is not running »
        fi
}

restart() {
        stop
        start
}      

case « $1 » in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart|reload)
                restart
                ;;
        *)
                echo $ »Usage: $0 {start|stop|restart} »
                exit 1
esac

exit $?

Ensuite effecuté un chmod 755 sur ce script
Lancez le.

Vous pouvez maintenant éditer votre crontab via le fichier /etc/crontab

posted under Actualités

Email will not be published

Website example

Your Comment:

Le temps imparti est dépassé. Merci de saisir de nouveau le CAPTCHA.