Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[TIP] ? - Salviamo i dati importanti di portage
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) Risorse italiane (documentazione e tools)
View previous topic :: View next topic  
Author Message
xchris
Advocate
Advocate


Joined: 10 Jul 2003
Posts: 2824

PostPosted: Thu Mar 17, 2005 9:25 am    Post subject: [TIP] ? - Salviamo i dati importanti di portage Reply with quote

Non sapevo se postare questa stupidata che ho scritto.
In realta' e' molto semplice ma troppo spesso ho visto sul forum persone perdere /etc/fstab o /var/db/pkg...

e' uno script stupido che sara' forse utile solo ai "principianti"
(in realta' con una riga si fa lo stesso lavoro)

va bhe.. scrivo lo stesso

Code:

#!/bin/bash
source /sbin/functions.sh

## maybe also /boot
FILES="/boot /etc /var/lib/portage /var/db/pkg /usr/local/portage"
ARCHIVE_DIR="/root"
#####
DATE=`date +"%Y%m%d-%H%M%S"`
BK_NAME="gentoo_safe.$DATE.tar.gz"

## we must be root!!
if  [ ! $UID -eq 0 ]
then
        eerror "You must be root!"
        exit
fi


### usefull functions
boot_mounted()
{
[ `grep /boot /etc/mtab| wc -l | cut -d" " -f1` -gt 0 ] && return 1 || return 0
}

need_to_mount()
{
[ `grep /boot /etc/fstab| wc -l | cut -d" " -f1` -gt 0 ] && return 1 || return 0
}
####

boot_mounted
PREVIOUSLY_MOUNTED=$?

need_to_mount
NEED_TO_MOUNT=$?



## let's try to mount boot if we need to
if [ $NEED_TO_MOUNT -eq 1 ] && [ $PREVIOUSLY_MOUNTED -eq 0 ]
then
        ebegin "Trying to mount boot"
        mount /boot &>/var/log/gentoo_safe.err
        eend $?
fi

ebegin "Making backup of $FILES in $ARCHIVE_DIR"
tar zcpf $ARCHIVE_DIR/$BK_NAME $FILES &>/var/log/gentoo_safe.err
eend $?

## let see if we have mounted it
boot_mounted
MOUNTED=$?

## let's try to return to initial situation
if [ $MOUNTED -eq 1 ] &&  [ $PREVIOUSLY_MOUNTED -eq 0 ]
then
        ebegin "Unmounting /boot"
        umount /boot &> /var/log/gentoo_safe.err
        eend $?
fi


edit: versione modificata su indicazioni riportate sotto.

e' talmente banale che nessuno ha mai avuto il coraggio di postarlo :lol:
ma salva il c**o spesso! ;)


Consiglio:salvate su partizioni diverse!
_________________
while True:Gentoo()


Last edited by xchris on Fri Apr 22, 2005 3:49 pm; edited 5 times in total
Back to top
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 30822
Location: here

PostPosted: Thu Mar 17, 2005 9:29 am    Post subject: Reply with quote

E invece lo trovo utilissimo io ne ho scritto uno ma molto peggio facevo solo dei cp. Grande xchris va direttamente in /usr/local/bin :D
_________________
Questions are guaranteed in life; Answers aren't.
Back to top
View user's profile Send private message
gutter
Bodhisattva
Bodhisattva


Joined: 13 Mar 2004
Posts: 7162
Location: Aarau, Aargau, Switzerland

PostPosted: Thu Mar 17, 2005 9:33 am    Post subject: Reply with quote

Fatto bene bravo ;)
_________________
Registered as User #281564 and Machines #163761
Back to top
View user's profile Send private message
randomaze
Bodhisattva
Bodhisattva


Joined: 21 Oct 2003
Posts: 9985

PostPosted: Thu Mar 17, 2005 9:56 am    Post subject: Re: [TIP] ? - Salviamo i dati importanti di portage Reply with quote

Salvato.
Ma ho modificato la linea:

xchris wrote:
DATE=`date | tr " " "-"`


Con una più civile:

Code:
date +"%Y%m%d-%H%M%S"


:-P

...ho anche aggiunto /usr/local/portage alle directory da backuppare ;-)
_________________
Ciao da me!
Back to top
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 30822
Location: here

PostPosted: Thu Mar 17, 2005 9:58 am    Post subject: Reply with quote

@randomaze: e postalo allora :P
_________________
Questions are guaranteed in life; Answers aren't.
Back to top
View user's profile Send private message
lavish
Bodhisattva
Bodhisattva


Joined: 13 Sep 2004
Posts: 4296

PostPosted: Thu Mar 17, 2005 10:00 am    Post subject: Re: [TIP] ? - Salviamo i dati importanti di portage Reply with quote

randomaze wrote:
[CUT]
...ho anche aggiunto /usr/local/portage alle directory da backuppare ;-)

E io ho messo anche /boot preoccupandomi di montarla prima (togliendola da quella condizione di incertezza :P )
Scriptino carino xchris ;) Grazie per il TIP
_________________
minimalblue.com | secgroup.github.io/
Back to top
View user's profile Send private message
xchris
Advocate
Advocate


Joined: 10 Jul 2003
Posts: 2824

PostPosted: Thu Mar 17, 2005 10:02 am    Post subject: Re: [TIP] ? - Salviamo i dati importanti di portage Reply with quote

randomaze wrote:
Salvato.
Ma ho modificato la linea:

xchris wrote:
DATE=`date | tr " " "-"`





eh la pigrizia...
man date...
LOL

ahem... stavo facendo anche io il mount del boot...
mettiamoci d'accordo che cosi' ne tiriamo fuori da consigliare sempre :)
_________________
while True:Gentoo()
Back to top
View user's profile Send private message
xchris
Advocate
Advocate


Joined: 10 Jul 2003
Posts: 2824

PostPosted: Thu Mar 17, 2005 10:33 am    Post subject: Reply with quote

l'ho sistemata un po' sotto vostro consiglio :)
vedete un po' :)

ciau
_________________
while True:Gentoo()
Back to top
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 30822
Location: here

PostPosted: Thu Mar 17, 2005 11:56 pm    Post subject: Reply with quote

Aggiunto ai post utilissimi sezione tips
_________________
Questions are guaranteed in life; Answers aren't.
Back to top
View user's profile Send private message
luna80
Veteran
Veteran


Joined: 01 Feb 2004
Posts: 1545
Location: switzerland

PostPosted: Fri Mar 18, 2005 7:32 am    Post subject: Reply with quote

molto utile :wink:

grazie anche da parte mia!
Back to top
View user's profile Send private message
hellraiser
Guru
Guru


Joined: 14 Jun 2003
Posts: 431
Location: Pescara [Italy]

PostPosted: Fri Apr 22, 2005 3:23 pm    Post subject: Reply with quote

Quote:

tar zcf $ARCHIVE_DIR/$BK_NAME $FILES &>/var/log/gentoo_safe.err


Non sarebbe meglio qualcosa del genere ??

Code:

tar zcpf $ARCHIVE_DIR/$BK_NAME $FILES &>/var/log/gentoo_safe.err


che cosi preserve i permessi dei file???
_________________
Io non sono nessuno...ma nessuno è come me!

"Open Source is a good idea..."
Back to top
View user's profile Send private message
xchris
Advocate
Advocate


Joined: 10 Jul 2003
Posts: 2824

PostPosted: Fri Apr 22, 2005 3:30 pm    Post subject: Reply with quote

giusta osservazione...

ho fatto qualche prova e sembra comunque mantenere i permessi.

dal man non ho capito se e' di default ma immagino di si.
ciao
_________________
while True:Gentoo()
Back to top
View user's profile Send private message
gutter
Bodhisattva
Bodhisattva


Joined: 13 Mar 2004
Posts: 7162
Location: Aarau, Aargau, Switzerland

PostPosted: Fri Apr 22, 2005 3:45 pm    Post subject: Reply with quote

xchris wrote:

dal man non ho capito se e' di default ma immagino di si.
ciao


Me lo sono sempre chiesto :roll:

Comunque metterla male non fa ;)
_________________
Registered as User #281564 and Machines #163761
Back to top
View user's profile Send private message
xchris
Advocate
Advocate


Joined: 10 Jul 2003
Posts: 2824

PostPosted: Fri Apr 22, 2005 3:50 pm    Post subject: Reply with quote

ok... messa a scanso di equivoci :)

ciao e grazie
_________________
while True:Gentoo()
Back to top
View user's profile Send private message
hellraiser
Guru
Guru


Joined: 14 Jun 2003
Posts: 431
Location: Pescara [Italy]

PostPosted: Fri Apr 22, 2005 5:41 pm    Post subject: Reply with quote

Figurati...è un piacere dare un piccolo contributo a questa MAGNIFICA comunita!
_________________
Io non sono nessuno...ma nessuno è come me!

"Open Source is a good idea..."
Back to top
View user's profile Send private message
sam75
n00b
n00b


Joined: 15 Nov 2004
Posts: 59

PostPosted: Sat Apr 23, 2005 9:17 pm    Post subject: Reply with quote

xchris wrote:
giusta osservazione...

ho fatto qualche prova e sembra comunque mantenere i permessi.

dal man non ho capito se e' di default ma immagino di si.
ciao


e' solo una supposizione, ma l'opzione "p" dovrebbe servire solamente per preservare i permessi quando si estraggono i files:
Dal man di tar:

Code:
-p, --same-permissions, --preserve-permissions
         extract all protection information

inoltre se si estrae come root l'opzione viene abilitata automaticamente.

Alcune brevi info si trovano anche qua: http://www.dbaoncall.net/references/ht_tar.html

EDIT:
inoltre trovi tutta la documentazione di tar su: http://www.gnu.org/software/tar/manual/html_mono/tar.htm
nella sezione 1.2 delle definizioni trovi:

Quote:
The tar program is used to create and manipulate tar archives. An archive is a single file which contains the contents of many files, while still identifying the names of the files, their owner(s), and so forth. (In addition, archives record access permissions, user and group, size in bytes, and last modification time. Some archives also record the file names in each archived directory, as well as other file and directory information.) You can use tar to create a new archive in a specified directory.

PS: per modificare il proprietario, il gruppo e i permessi si usano le opzioni:
--owner= , --group= e --mode=

... sempre che l'implementazione di tar sia quella GNU.

ciao
Back to top
View user's profile Send private message
xchris
Advocate
Advocate


Joined: 10 Jul 2003
Posts: 2824

PostPosted: Sun Apr 24, 2005 7:22 am    Post subject: Reply with quote

bhe ecco svelato il mistero :)

grazie per la precisazione.
(effettivamente da root non ho mai messo -p)

Possiamo cmq lasciarlo nello script... cosi' a nessuno viene il dubbio :)

Ciao
_________________
while True:Gentoo()
Back to top
View user's profile Send private message
gutter
Bodhisattva
Bodhisattva


Joined: 13 Mar 2004
Posts: 7162
Location: Aarau, Aargau, Switzerland

PostPosted: Mon Apr 25, 2005 8:29 pm    Post subject: Reply with quote

xchris wrote:

Possiamo cmq lasciarlo nello script... cosi' a nessuno viene il dubbio :)


Si meglio così :)
_________________
Registered as User #281564 and Machines #163761
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) Risorse italiane (documentazione e tools) 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