Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[script] petite sauvegarde polyvalente
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
philius
n00b
n00b


Joined: 13 Aug 2009
Posts: 61
Location: sur la route, j'arrive !

PostPosted: Wed Aug 19, 2009 1:22 pm    Post subject: [script] petite sauvegarde polyvalente Reply with quote

un script me permettant une multitude de restauration
- pour sauvegarder simplement mon système
- pour changer de disque dur / modifier le partitionnement / le type de filesystem
- repartir à zéro sur une installation en gardant ma configuration
- faire des tests en partant d'une copie de mon système sur une partition libre

*****
#!/bin/bash

chaine=/data/sauvegarde/$(date +%d%B%Y-%Hh%Mm%Ss)-total

mkdir $chaine

tar cpjf $chaine/system.tar.bz2 --exclude=/var/run/* --exclude=/var/log/* --exclude=/chroot --exclude=/home --exclude=/boot --exclude=/proc --exclude=/tmp --exclude=/sys --exclude=/lost+found --exclude=/data --exclude=/media --exclude=/usr/portage/distfiles /

tar cpjf $chaine/conf.tar.bz2 /*.maj /etc/resolv.conf /etc/make.conf /etc/fstab /etc/rc.conf /etc/hosts /etc/conf.d/hostname /etc/conf.d/domainname /etc/conf.d/net /etc/conf.d/keymaps /etc/conf.d/consolefont /etc/portage/package.use /etc/portage/package.keywords /etc/conf.d/clock /etc/hal/fdi/policy/10-keymap.fdi /etc/env.d/02locale /etc/localtime /etc/locale.gen /var/lib/portage/world /etc/X11/xorg.conf /etc/modules.autoload.d/kernel-2.6 /usr/src/linux-$(uname -r)/compiler /usr/src/linux-$(uname -r)/.config

tar cpjf $chaine/boot.tar.bz2 /boot

tar cpjf $chaine/home.tar.bz2 /home

echo "tar xpfj $chaine/boot.tar.bz2 -C /chroot/" >> $chaine/restauration.boot
echo "tar xpfj $chaine/home.tar.bz2 -C /chroot" >> $chaine/restauration.home
echo "tar xpfj $chaine/conf.tar.bz2 -C /chroot" >> $chaine/restauration.conf

echo "tar xpfj $chaine/system.tar.bz2 -C /chroot/" >> $chaine/restauration.total
echo "tar xpfj $chaine/boot.tar.bz2 -C /chroot/" >> $chaine/restauration.total
echo "tar xpfj $chaine/home.tar.bz2 -C /chroot" >> $chaine/restauration.total

echo "mkdir /chroot/proc" >> $chaine/restauration.total
echo "chmod 555 /chroot/proc" >> $chaine/restauration.total

echo "mkdir /chroot/tmp" >> $chaine/restauration.total
echo "chmod 1777 /chroot/tmp" >> $chaine/restauration.total

echo "mkdir /chroot/sys" >> $chaine/restauration.total
echo "chmod 755 /chroot/sys" >> $chaine/restauration.total

echo "mkdir /chroot/lost+found" >> $chaine/resaouttauration.total
echo "chmod 700 /chroot/lost+found" >> $chaine/restauration.total

echo "mkdir /chroot/media" >> $chaine/restauration.total
echo "chmod 755 /chroot/media" >> $chaine/restauration.total

echo "mkdir /chroot/data" >> $chaine/restauration.total
echo "chmod 757 /chroot/data" >> $chaine/restauration.total

echo "echo à vérifier fstab selon le point de restauration et éventuellement boot" >> $chaine/restauration.total

chmod u+x $chaine/restauration*

******

ce qui va me générer un répertoire de la forme 19aout2009-14h41m10s dans /data
j'ai inclue jusqu'au seconde simplement pour éviter d'écraser le répertoire dans le cas ou en faisant une erreur de manipulation je relance le script
déjà testé cette erreur et je me suis retrouvé à écraser une sauvegarde (et donc tout perdre) en sauvegardant un live cd lol par dessus :D

dans le répertoire ->
boot.tar.bz2
conf.tar.bz2
system.tar.bz2

et les scripts de restauration
restauration.boot
restauration.conf
restauration.home
restauration.total

exemple pour restauration.total

tar xpfj /data/sauvegarde/15août2009-02h48m04s-total/system.tar.bz2 -C /chroot/
tar xpfj /data/sauvegarde/15août2009-02h48m04s-total/boot.tar.bz2 -C /chroot/
tar xpfj /data/sauvegarde/15août2009-02h48m04s-total/home.tar.bz2 -C /chroot
mkdir /chroot/proc
chmod 555 /chroot/proc
mkdir /chroot/tmp
chmod 1777 /chroot/tmp
mkdir /chroot/sys
chmod 755 /chroot/sys
mkdir /chroot/lost+found
chmod 700 /chroot/lost+found
mkdir /chroot/media
chmod 755 /chroot/media
mkdir /chroot/data
chmod 757 /chroot/data
echo à vérifier fstab selon le point de restauration et éventuellement boot

je restaure toujours sur une partition monté dans /chroot en partant d'un live-cd ou d'un système lancé sur une autre partition
et mes data et sauvegardes ne sont pas dans mon home mais sur une partition dédié (moins contraignant dans le cas de modification)
le répertoire /data est autorisé pour mon compte utilisateur

pour mes /data j'utilise juste une réplication sur un disque dur usb externe en utilisant rsync

rsync -rltvuE --delete --exclude='lost+found' --exclude='.Trash-1000' /data/ /media/disk/data/

je ne garde pas les droits et permission sur les fichiers pour éviter d'éventuels problèmes de droits par la suite

si je veux repartir à zéro
en partant d'un live-cd ou d'un système lancé sur une autre partition
je télécharge le dernier stage et le dernier portage + mon conf.tar.bz2
je décompresse le tout dans une partition
édite fstab/make.conf/wolrd etc... pour faire des modifications si nécéssaire
et un simple emerge wolrd+system va me régénérer une installation identique ou avec quelques modifications

petit script pour repartir à zéro je dépose le tout archive + script dans un répertoire "installation" sur ma partition monté dans /chroot

tar -xjpf /chroot/installation/stage3* -C /chroot

tar -xjf /chroot/installation/portage* -C /chroot/usr

tar -xjf /chroot/installation/conf* -C /chroot

mkdir /chroot/data
chmod 757 /chroot/data

cp /etc/mtab /chroot/etc/mtab

mount -o bind /proc /chroot/proc
mount -o bind /dev /chroot/dev

chroot /chroot /bin/bash

****

ensuite une fois basculé dans le chroot un deuxième script

echo "tapez le password pour root"
passwd

locale-gen

env-update
source /etc/profile

emerge --sync

emerge gentoo-sources

echo compiler le noyau maintenant

arrivé la je peux démarré sur mon système de base en rajoutant grub
puis il ne me reste plus qu'a régénerer mon système par un 3eme et dernier script

emerge -ea --deep --newuse world system

eselect opengl set nvidia

rc-update add net.eth0 default
rc-update add sysklogd default
rc-update add vixie-cron default
rc-update add cupsd default
rc-update add dbus default
rc-update add keymaps boot
rc-update add hald default
rc-update add alsasound boot
locate -u /var/lib/slocate/slocate.db


voila avec tout cela je peux faire ce que je veux sur ma machine

sur dual core 2.3ghz
la sauvegarde prend 20mn
la restauration 6mn
la réinstallation 6heures (520 paquets)

mon post est un peu brouillon peut être ?
mais j'apporte juste une idée de départ à adapter bien sûr sur les chemins des scripts et selon vos besoin

pour ma part un partitionnement

/boot
/
/swap
/data
/partion libre pour test ou système de maintenance

me permet des modifications et test à volonté

mon disque usb externe est un plus avec un live-cd
Back to top
View user's profile Send private message
El_Goretto
Moderator
Moderator


Joined: 29 May 2004
Posts: 3166
Location: Paris

PostPosted: Thu Sep 03, 2009 4:01 pm    Post subject: Reply with quote

Peux-tu détailler l'intérêt de ton script par rapport à l'ancestral stage4 ?
_________________
-TrueNAS & jails: µ-serv Gen8 E3-1260L, 16Go ECC + µ-serv N40L, 10Go ECC
-Réseau: APU2C4 (OpenWRT) + GS726Tv3 + 2x GS108Tv2 + Archer C5v1 (OpenWRT)
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Sat Sep 05, 2009 2:51 pm    Post subject: Reply with quote

Désolé, j'n'ai pas lu, mais y'a juste le chmod 757 qui me fait bizarrre... C'est une erreur n'est-ce pas? ou alors je veux bien un explication :)
_________________
The End of the Internet!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum