Wiki Ubuntu-it

Indice
Partecipa
FAQ
Wiki Blog
------------------
Ubuntu-it.org
Forum
Chiedi
Chat
Cerca
Planet
  • Pagina non alterabile
  • Informazioni
  • Allegati
  • Differenze per "AmministrazioneSistema/BackupDelSistema/BackupConTar"
Differenze tra le versioni 1 e 60 (in 59 versioni)
Versione 1 del 23/11/2005 19.46.24
Dimensione: 9320
Commento: Importato il documento originale
Versione 60 del 14/06/2021 13.44.12
Dimensione: 6613
Commento:
Le cancellazioni sono segnalate in questo modo. Le aggiunte sono segnalate in questo modo.
Linea 1: Linea 1:
'''Note: This page needs work. Use at your own risk. It is recommended that you read the whole page before doing anything''' ## page was renamed from BackupDelSistema/BackupConTar
#LANGUAGE it
#format wiki
<<BR>>
<<Indice(depth=2)>>
<<Informazioni(forum="https://forum.ubuntu-it.org/viewtopic.php?f=46&t=599983"; rilasci="20.04 18.04")>>
= Introduzione =
Linea 3: Linea 9:
This guide to backup your system using tar to create compressed archives was taken from the post on the Ubuntu Forum written by Heliode. See the thread for discussion: http://www.ubuntuforums.org/showthread.php?t=35087 Con '''Ubuntu''' è possibile eseguire un backup dell'intero sistema con gli stessi strumenti utilizzati per archiviare o comprimere ogni altro file: '''tar'''.
Linea 5: Linea 11:
[[TableOfContents]] = Installazione =
Linea 7: Linea 13:
== Introduction == '''tar''' è già preinstallato nel sistema Ubuntu.<<BR>>
Nel caso non fosse presente, è sufficiente [[AmministrazioneSistema/InstallareProgrammi|installare]] il pacchetto [[apt://tar|tar]].
Linea 9: Linea 16:
Hi, and welcome to the Heliode guide to successful backing-up and restoring of a Linux system! = Procedimento backup =
Linea 11: Linea 18:
Most of you have probably used Windows before you started using Ubuntu. During that time you might have needed to backup and restore your system. For Windows you would need proprietary software for which you would have to reboot your machine and boot into a special environment in which you could perform the backing-up/restoring (programs like Norton Ghost).
During that time you might have wondered why it wasn't possible to just add the whole c:\ to a big zip-file. This is impossible because in Windows, there are lots of files you can't copy or overwrite while they are being used, and therefore you needed specialized software to handle this.
Per eseguire un backup dell'intero sistema, partendo dalla directory root `/`, è necessario utilizzare i [[AmministrazioneSistema/PrivilegiDiAmministrazione|privilegi di amministratore]] in un [[AmministrazioneSistema/Terminale|terminale]].
Linea 14: Linea 20:
Well, I'm here to tell you that those things, just like rebooting, are Windows Crazy Things (tm). There's no need to use programs like Ghost to create backups of your Ubuntu system (or any Linux system, for that matter). In fact; using Ghost might be a very bad idea if you are using anything but ext2. Ext3, the default Ubuntu partition, is seen by Ghost as a damaged ext2 partition and does a very good job at screwing up your data.

== Backing-up ==

"What should I use to backup my system then?" might you ask. Easy; the same thing you use to backup/compress everything else; TAR. Unlike Windows, Linux doesn't restrict root access to anything, so you can just throw every single file on a partition in a TAR file!

To do this, become root with

{{{
sudo su
 0. Spostarsi nella directory o partizione di destinazione del backup, digitando in un [[AmministrazioneSistema/Terminale|terminale]] il comando: {{{
cd `/directory_destinazione_backup`
}}}
 0. Per effettuare il backup del sistema `/` digitare il seguente comando: {{{
sudo tar -cvpzf /backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys /
Linea 26: Linea 27:
and go to the root of your filesystem (we use this in our example, but you can go anywhere you want your backup to end up, including remote or removable drives.) Di seguito è riportata in dettaglio la spiegazione della sintassi del comando:
Linea 28: Linea 29:
{{{
cd /
<<Anchor(sintassi)>>

||<tablestyle="width: 70%;" rowstyle="background-color: #cccccc;" 20%:>'''Opzione'''||<80%:> '''Risultato''' ||
||<:>'''tar''' || È il programma di archiviazione utilizzato per eseguire il backup. ||
||<:>'''-c''' || Crea un nuovo archivio di backup. ||
||<:>'''-v''' || Modalità verbose: '''tar''' restituisce sullo schermo una descrizione delle operazioni in corso. ||
||<:>'''-p''' || Mantiene i permessi di tutti i file. ||
||<:>'''-z''' || Comprime il file di backup con '''gzip''' per renderlo più piccolo. ||
||<:>'''-f <nomefile>''' || Specifica dove salvare il backup (`/backup.tgz` è il file utilizzato in questo esempio). ||
||<:>'''--exclude=/<dir>''' || Esclude dal backup la directory specificata. ||
||<:>'''/''' || Specifica '''/''' come directory di backup (`/`, root). ||

== Esclusione directory ==

Si consiglia di non includere le cartelle di sistema `/mnt` e `/media`, poiché nel caso siano presenti altre partizioni montate verrebbe eseguito il backup anche di queste.


{{{#!wiki note
Non è necessario fare il backup di tutto il sistema poiché alcune directory non sono indispensabili (compreso il file di backup stesso).
Linea 32: Linea 50:
Now, below is the full command I would use to make a backup of my system:
Linea 34: Linea 51:
== Aggiungere la data ==

Al nome del file di backup è possibile aggiungere la data di esecuzione dello stesso. A tale scopo è sufficiente aggiungere la seguente dicitura al comando di backup:
Linea 35: Linea 55:
tar -cvpzf /backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys / `date +%d-%m-%Y`
Linea 38: Linea 58:
Now, lets explain this a little bit:
 * 'tar' is the program used to do a backup
 * c - create a new backup archive
 * v - verbose mode, tar will print what it's doing to the screen
 * p - preserve permissions, keeps all file permissions the same
 * z - compress the backup file with 'gzip' to make it smaller
 * f <filename> - specifies where to store the backup, /backup.tgz is the file used in this example
 * Now come the directories we want to exclude. We don't want to backup everything since some dirs aren't very useful to include. Also make sure you don't include the file itself, or else you'll get weird results. You might also not want to include the /mnt folder if you have other partitions mounted there or you'll end up backing those up too. Also make sure you don't have anything mounted in /media (i.e. don't have any cd's or removable media mounted). Either that or exclude /media.
 * After all of the options is the directory we want to backup. Since we want to backup everything we use / for the root directory

If you want to exclude all other filesystems you can use the 'l' option instead of --exclude. The above command would thus be:
Il comando aggiungerà al nome del file una data in formato «giorno-mese-anno», simile al seguente esempio:
Linea 51: Linea 60:
tar -cvpzlf /backup.tgz --exclude=/lost+found --exclude=/backup.tgz / sudo tar -cvpjf /backup-`date+%d-%m-%Y`.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup-`date+%d-%m-%Y`.tar.bz2 --exclude=/mnt --exclude=/sys /
Linea 54: Linea 63:
EDIT: kvidell suggests on the forum thread that we also exclude the /dev directory. I have other evidence that says it is very unwise to do so though. = Compressione della directory =
Linea 56: Linea 65:
Well, if the command agrees with you, hit enter (or return, whatever) and sit back & relax. This might take a while. È possibile anche utilizzare '''bzip2''' per comprimere il file di backup. Questo porta un maggiore compressione, seppur a discapito di una minore velocità.
Linea 58: Linea 67:
Afterwards you'll have a file called backup.tgz, which is probably pretty large, in the root of your filesytem. Now you can burn it to DVD or move it to another machine; whatever you like!

attachment:IconsPage/IconWarning3.png WARNING: Files that are bigger than 2GB (a little less actually) are not supported by ISO9660 and may or may not be restorable. So don't simply burn a DVD with a huge .iso file on it. Split it up using the command split (see man page) or use a different way to get it onto the DVD. One possiblity (untested) is the following:

{{{
sudo tar --create --bzip2 --exclude /tmp --one-file-system --sparse / | growisofs -use-the-force-luke -Z /dev/hda=/proc/self/fd/0
Per utilizzare '''bzip2''' sostituire nel comando di creazione del backup l'opzione '''z''' con '''j''' e modificare l'estensione del file di backup, come nel seguente esempio: {{{
sudo tar -cvpjf /backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /
Linea 66: Linea 71:
Note that this only backs up one file system. You might want to use --exclude instead of --one-file-system to filter out the stuff you don't want backed up. This assumes your DVD drive is /dev/hda. This will not create a mountable DVD. To restore it you will reference the device file: = Ripristino =
Linea 68: Linea 73:
{{{
sudo tar --extract --bzip2 --file /dev/hda
{{{#!wiki important
Prestare molta attenzione alle istruzioni seguenti, poiché in caso di errori si possono sovrascrivere file importanti per il sistema. Il comando seguente sovrascriverà tutti i file del sistema con quelli presenti nell'archivio di backup.}}}

Per ripristinare il backup non c'è bisogno di entrare in una modalità speciale del sistema operativo, infatti è possibile farlo con il sistema in esecuzione. Nel caso in cui non si riesca ad accedere al sistema, è possibile utilizzare un DVD/USB live per ottenere gli stessi risultati.

È possibile rimuovere qualsiasi file dal sistema mentre questo è in esecuzione, con tutto ciò che questo comporta al successivo riavvio.

 0. Copiare il file di backup nella directory `/`.

 0. Per eseguire il ripristino, digitare il seguente comando in un terminale: {{{
sudo tar -xvpzf /backup.tgz -C /
}}}
 Nel caso in cui sia stato utilizzato '''bunzip2''', digitare invece il seguente comando: {{{
sudo tar -xvpjf backup.tar.bz2 -C /
}}} Alcune opzioni:
  * '''x''': serve per estrarre i file nell'archivio
  * '''-C <directory>''': serve per spostarsi in una specifica directory, in questo caso `/`, prima di estrarre i file.

 0. Premere '''Invio''' per avviare il ripristino.

 0. Al termine della procedura, assicurarsi di ricreare eventuali directory escluse durante il backup nel caso siano state compromesse (ad esempio `/proc`, `/lost+found`, `/mnt`, `/sys` ecc.): {{{
sudo mkdir /proc /lost+found /mnt /sys
Linea 72: Linea 97:
EDIT2:
At the end of the process you might get a message along the lines of 'tar: Error exit delayed from previous errors' or something, but in most cases you can just ignore that.
Al successivo riavvio tutto il sistema sarà stato ripristinato.
Linea 75: Linea 99:
Alternatively, you can use Bzip2 to compress your backup. This means higher compression but lower speed. If compression is important to you, just substitute
the 'z' in the command with 'j', and give the backup the right extension.
That would make the command look like this:
= Backup attraverso la rete =
Linea 79: Linea 101:
{{{
tar -cvpjf /backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /
}}}
Qualora il disco fisso non abbia abbastanza spazio o non fosse possibile montarne un altro in cui salvare il backup, è possibile usare '''netcat''' per spostare il file di backup.
Linea 83: Linea 103:
=== Backup over network ===

If the filesystem is low on space and you can't mount another filesystem to store the backup file on it is
possible to use netcat to trasfer the backup.

On the receiving end you'll setup netcat to write the backup file like this:

{{{
Dalla parte del ricevente, impostare '''netcat''' in modo da scrivere il backup in questo modo: {{{
Linea 94: Linea 107:
Then you pipe the tar command without the 'f' flag through netcat on the sending end like this:

{{{
tar -cvpj <all those other options> / | nc -q 0 <receiving host> 1024
Quindi mettere in pipe il comando per eseguire il backup con '''netcat''', senza il flag '''f''', come in questo esempio: {{{
sudo tar -cvpj <tutte le altre opzioni> / | nc -q 0 <host di ricezione> 1024
Linea 100: Linea 111:
In the above commands 1024 is just a random portnumber, anything from 1024 and up should work.

If all goes well the backup will be piped through the network without touching the filesystem being read.
With a really fast network this could actually be faster then writing the backup file back to disk.

A variation (which I just dreamed up, so I can't testify on its reliability) on the above is this command:

{{{
tar -cvpj <all those other options> / | ssh <remote host> "cat > backup.tar.bz2"
{{{#!wiki note
«1024» si riferisce al numero di una porta. Utilizzare un numero pari a 1024 o superiore.
Linea 111: Linea 115:
== Restoring ==
Linea 113: Linea 116:
attachment:IconsPage/IconWarning3.png Warning: Please, for goodness sake, be careful here. If you don't understand what you are doing here you might end up overwriting stuff that is important to you, so please take care! Se tutto è andato a buon fine il backup sarà inviato in pipe attraverso la rete. La scrittura del file su disco sarà più rapida se in uso una rete veloce.
Linea 115: Linea 118:
Well continue with our example from the previous chapter which created the file backup.tgz in the root directory. = Programmare il backup con cron =
Linea 117: Linea 120:
Once again, make sure you are root and that you and the backup file are in the root of the filesystem. L'esecuzione di queste operazioni può essere programmata e resa automatica con '''cron'''. Per maggiori informazioni consultare [[AmministrazioneSistema/Cron|questa guida]].
Linea 119: Linea 122:
One of the beautiful things of Linux is that this will even work on a running system; no need to screw around with boot-cd's or anything. Of course, if you've rendered your system unbootable you might have no choice but to use a live cd but the results are the same. You can even remove every single file of a Linux system while it is running with one command. I'm not giving you that command though! = Ulteriori risorse =
Linea 121: Linea 124:
Well, back on-topic.
This is the command that I would use:
 * [[Ubuntu:BackupYourSystem|Documento originale]]
 * [[http://www.ubuntuforums.org/showthread.php?t=35087|Guida sul forum internazionale]]
 * [[https://it.wikipedia.org/wiki/Tar_(software)|Tar (wikipedia)]]
 * [[AmministrazioneSistema/FormatiDiCompressione|Formati di compressione]]
Linea 124: Linea 129:
{{{
tar -xvpzf /backup.tgz -C /
}}}

Or if you used bz2;

{{{
tar -xvpjf backup.tar.bz2 -C /
}}}

The x option tells tar to extract the file. The -C <directory> option tells tar to change to a specific directory ( / in this example ) before extracting.

attachment:IconsPage/IconWarning3.png WARNING: this will overwrite every single file on your partition with the one in the archive!

Just hit enter/return/your brother/whatever and watch the fireworks. Again, this might take a while. When it is done, you have a fully restored Ubuntu system! Just make sure that, before you do anything else, you re-create the directories were excluded ( /proc, /lost+found, /mnt, /sys, etc.).

{{{
mkdir /proc /lost+found /mnt /sys
}}}

And when you reboot, everything should be the way it was when you made the backup!

=== GRUB restore ===

Now, if you want to move your system to a new harddisk or if you did something nasty to your GRUB (like, say, install Windows), You'll also need to reinstall GRUB.
There are several very good howto's on how to do that here on this forum, so i'm not going to reinvent the wheel. Instead, take a look [http://www.ubuntuforums.org/showthread.php?t=24113&highlight=grub+restore here] (forum) or here: RecoveringUbuntuAfterInstallingWindows

On the forum thread, there are a couple of methods proposed. I personally recommend the second one, posted by remmelt, since that has always worked for me.

Well that's it! I hope it was helpful!

== Other Methods ==

You might also want to check out these backup programs which will help you to make automated backups of your system:
 * [http://www.partimage.org/ Partimage]
 * [http://www.mondorescue.org/ Mondo Rescue]

CategoryDocumentation CategoryCleanup

See the full discussion in this thread on the Ubuntu forums. http://www.ubuntuforums.org/showthread.php?t=70566
----
CategoryAmministrazione


Guida verificata con Ubuntu: 20.04

Problemi in questa pagina? Segnalali in questa discussione

Introduzione

Con Ubuntu è possibile eseguire un backup dell'intero sistema con gli stessi strumenti utilizzati per archiviare o comprimere ogni altro file: tar.

Installazione

tar è già preinstallato nel sistema Ubuntu.
Nel caso non fosse presente, è sufficiente installare il pacchetto tar.

Procedimento backup

Per eseguire un backup dell'intero sistema, partendo dalla directory root /, è necessario utilizzare i privilegi di amministratore in un terminale.

  1. Spostarsi nella directory o partizione di destinazione del backup, digitando in un terminale il comando:

    cd `/directory_destinazione_backup`
  2. Per effettuare il backup del sistema / digitare il seguente comando:

    sudo tar -cvpzf /backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys /

Di seguito è riportata in dettaglio la spiegazione della sintassi del comando:

Opzione

Risultato

tar

È il programma di archiviazione utilizzato per eseguire il backup.

-c

Crea un nuovo archivio di backup.

-v

Modalità verbose: tar restituisce sullo schermo una descrizione delle operazioni in corso.

-p

Mantiene i permessi di tutti i file.

-z

Comprime il file di backup con gzip per renderlo più piccolo.

-f <nomefile>

Specifica dove salvare il backup (/backup.tgz è il file utilizzato in questo esempio).

--exclude=/<dir>

Esclude dal backup la directory specificata.

/

Specifica / come directory di backup (/, root).

Esclusione directory

Si consiglia di non includere le cartelle di sistema /mnt e /media, poiché nel caso siano presenti altre partizioni montate verrebbe eseguito il backup anche di queste.

Non è necessario fare il backup di tutto il sistema poiché alcune directory non sono indispensabili (compreso il file di backup stesso).

Aggiungere la data

Al nome del file di backup è possibile aggiungere la data di esecuzione dello stesso. A tale scopo è sufficiente aggiungere la seguente dicitura al comando di backup:

`date +%d-%m-%Y`

Il comando aggiungerà al nome del file una data in formato «giorno-mese-anno», simile al seguente esempio:

sudo tar -cvpjf /backup-`date+%d-%m-%Y`.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup-`date+%d-%m-%Y`.tar.bz2 --exclude=/mnt --exclude=/sys /

Compressione della directory

È possibile anche utilizzare bzip2 per comprimere il file di backup. Questo porta un maggiore compressione, seppur a discapito di una minore velocità.

Per utilizzare bzip2 sostituire nel comando di creazione del backup l'opzione z con j e modificare l'estensione del file di backup, come nel seguente esempio:

sudo tar -cvpjf /backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /

Ripristino

Prestare molta attenzione alle istruzioni seguenti, poiché in caso di errori si possono sovrascrivere file importanti per il sistema. Il comando seguente sovrascriverà tutti i file del sistema con quelli presenti nell'archivio di backup.

Per ripristinare il backup non c'è bisogno di entrare in una modalità speciale del sistema operativo, infatti è possibile farlo con il sistema in esecuzione. Nel caso in cui non si riesca ad accedere al sistema, è possibile utilizzare un DVD/USB live per ottenere gli stessi risultati.

È possibile rimuovere qualsiasi file dal sistema mentre questo è in esecuzione, con tutto ciò che questo comporta al successivo riavvio.

  1. Copiare il file di backup nella directory /.

  2. Per eseguire il ripristino, digitare il seguente comando in un terminale:

    sudo tar -xvpzf /backup.tgz -C /

    Nel caso in cui sia stato utilizzato bunzip2, digitare invece il seguente comando:

    sudo tar -xvpjf backup.tar.bz2 -C /
    Alcune opzioni:
    • x: serve per estrarre i file nell'archivio

    • -C <directory>: serve per spostarsi in una specifica directory, in questo caso /, prima di estrarre i file.

  3. Premere Invio per avviare il ripristino.

  4. Al termine della procedura, assicurarsi di ricreare eventuali directory escluse durante il backup nel caso siano state compromesse (ad esempio /proc, /lost+found, /mnt, /sys ecc.):

    sudo mkdir /proc /lost+found /mnt /sys

Al successivo riavvio tutto il sistema sarà stato ripristinato.

Backup attraverso la rete

Qualora il disco fisso non abbia abbastanza spazio o non fosse possibile montarne un altro in cui salvare il backup, è possibile usare netcat per spostare il file di backup.

Dalla parte del ricevente, impostare netcat in modo da scrivere il backup in questo modo:

nc -l -p 1024 > backup.tar.bz2

Quindi mettere in pipe il comando per eseguire il backup con netcat, senza il flag f, come in questo esempio:

sudo tar -cvpj <tutte le altre opzioni> / | nc -q 0 <host di ricezione> 1024

«1024» si riferisce al numero di una porta. Utilizzare un numero pari a 1024 o superiore.

Se tutto è andato a buon fine il backup sarà inviato in pipe attraverso la rete. La scrittura del file su disco sarà più rapida se in uso una rete veloce.

Programmare il backup con cron

L'esecuzione di queste operazioni può essere programmata e resa automatica con cron. Per maggiori informazioni consultare questa guida.

Ulteriori risorse


CategoryAmministrazione