特殊:Badtitle/NS100:BackupYourSystem/TAR/zh:修订间差异
Chenfengyuan(留言 | 贡献) |
Chenfengyuan(留言 | 贡献) |
||
第8行: | 第8行: | ||
|} | |} | ||
{|border="1" cellspacing="0" | {|border="1" cellspacing="0" | ||
|https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=stop.png | |https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=stop.png 如果你没有正确使用程序来备份,那你的资料可能就会被你抹去了。所以请在读完后再动手 | ||
|} | |} | ||
=== 介绍 === | === 介绍 === |
2009年6月25日 (四) 09:31的最新版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/BackupYourSystem/TAR }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/af | • {{#if: UbuntuHelp:BackupYourSystem/TAR|Afrikaans| [[::BackupYourSystem/TAR/zh/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/ar | • {{#if: UbuntuHelp:BackupYourSystem/TAR|العربية| [[::BackupYourSystem/TAR/zh/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/az | • {{#if: UbuntuHelp:BackupYourSystem/TAR|azərbaycanca| [[::BackupYourSystem/TAR/zh/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/bcc | • {{#if: UbuntuHelp:BackupYourSystem/TAR|جهلسری بلوچی| [[::BackupYourSystem/TAR/zh/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/bg | • {{#if: UbuntuHelp:BackupYourSystem/TAR|български| [[::BackupYourSystem/TAR/zh/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/br | • {{#if: UbuntuHelp:BackupYourSystem/TAR|brezhoneg| [[::BackupYourSystem/TAR/zh/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/ca | • {{#if: UbuntuHelp:BackupYourSystem/TAR|català| [[::BackupYourSystem/TAR/zh/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/cs | • {{#if: UbuntuHelp:BackupYourSystem/TAR|čeština| [[::BackupYourSystem/TAR/zh/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/de | • {{#if: UbuntuHelp:BackupYourSystem/TAR|Deutsch| [[::BackupYourSystem/TAR/zh/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/el | • {{#if: UbuntuHelp:BackupYourSystem/TAR|Ελληνικά| [[::BackupYourSystem/TAR/zh/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/es | • {{#if: UbuntuHelp:BackupYourSystem/TAR|español| [[::BackupYourSystem/TAR/zh/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/fa | • {{#if: UbuntuHelp:BackupYourSystem/TAR|فارسی| [[::BackupYourSystem/TAR/zh/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/fi | • {{#if: UbuntuHelp:BackupYourSystem/TAR|suomi| [[::BackupYourSystem/TAR/zh/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/fr | • {{#if: UbuntuHelp:BackupYourSystem/TAR|français| [[::BackupYourSystem/TAR/zh/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/gu | • {{#if: UbuntuHelp:BackupYourSystem/TAR|ગુજરાતી| [[::BackupYourSystem/TAR/zh/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/he | • {{#if: UbuntuHelp:BackupYourSystem/TAR|עברית| [[::BackupYourSystem/TAR/zh/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/hu | • {{#if: UbuntuHelp:BackupYourSystem/TAR|magyar| [[::BackupYourSystem/TAR/zh/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/id | • {{#if: UbuntuHelp:BackupYourSystem/TAR|Bahasa Indonesia| [[::BackupYourSystem/TAR/zh/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/it | • {{#if: UbuntuHelp:BackupYourSystem/TAR|italiano| [[::BackupYourSystem/TAR/zh/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/ja | • {{#if: UbuntuHelp:BackupYourSystem/TAR|日本語| [[::BackupYourSystem/TAR/zh/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/ko | • {{#if: UbuntuHelp:BackupYourSystem/TAR|한국어| [[::BackupYourSystem/TAR/zh/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/ksh | • {{#if: UbuntuHelp:BackupYourSystem/TAR|Ripoarisch| [[::BackupYourSystem/TAR/zh/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/mr | • {{#if: UbuntuHelp:BackupYourSystem/TAR|मराठी| [[::BackupYourSystem/TAR/zh/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/ms | • {{#if: UbuntuHelp:BackupYourSystem/TAR|Bahasa Melayu| [[::BackupYourSystem/TAR/zh/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/nl | • {{#if: UbuntuHelp:BackupYourSystem/TAR|Nederlands| [[::BackupYourSystem/TAR/zh/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/no | • {{#if: UbuntuHelp:BackupYourSystem/TAR|norsk| [[::BackupYourSystem/TAR/zh/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/oc | • {{#if: UbuntuHelp:BackupYourSystem/TAR|occitan| [[::BackupYourSystem/TAR/zh/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/pl | • {{#if: UbuntuHelp:BackupYourSystem/TAR|polski| [[::BackupYourSystem/TAR/zh/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/pt | • {{#if: UbuntuHelp:BackupYourSystem/TAR|português| [[::BackupYourSystem/TAR/zh/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/ro | • {{#if: UbuntuHelp:BackupYourSystem/TAR|română| [[::BackupYourSystem/TAR/zh/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/ru | • {{#if: UbuntuHelp:BackupYourSystem/TAR|русский| [[::BackupYourSystem/TAR/zh/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/si | • {{#if: UbuntuHelp:BackupYourSystem/TAR|සිංහල| [[::BackupYourSystem/TAR/zh/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/sq | • {{#if: UbuntuHelp:BackupYourSystem/TAR|shqip| [[::BackupYourSystem/TAR/zh/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/sr | • {{#if: UbuntuHelp:BackupYourSystem/TAR|српски / srpski| [[::BackupYourSystem/TAR/zh/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/sv | • {{#if: UbuntuHelp:BackupYourSystem/TAR|svenska| [[::BackupYourSystem/TAR/zh/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/th | • {{#if: UbuntuHelp:BackupYourSystem/TAR|ไทย| [[::BackupYourSystem/TAR/zh/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/tr | • {{#if: UbuntuHelp:BackupYourSystem/TAR|Türkçe| [[::BackupYourSystem/TAR/zh/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/vi | • {{#if: UbuntuHelp:BackupYourSystem/TAR|Tiếng Việt| [[::BackupYourSystem/TAR/zh/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/yue | • {{#if: UbuntuHelp:BackupYourSystem/TAR|粵語| [[::BackupYourSystem/TAR/zh/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/zh | • {{#if: UbuntuHelp:BackupYourSystem/TAR|中文| [[::BackupYourSystem/TAR/zh/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/zh-hans | • {{#if: UbuntuHelp:BackupYourSystem/TAR|中文(简体)| [[::BackupYourSystem/TAR/zh/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:BackupYourSystem/TAR | UbuntuHelp:BackupYourSystem/TAR | {{#if: | :}}BackupYourSystem/TAR/zh}}/zh-hant | • {{#if: UbuntuHelp:BackupYourSystem/TAR|中文(繁體)| [[::BackupYourSystem/TAR/zh/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:BackupYourSystem/TAR|:BackupYourSystem/TAR/zh|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :BackupYourSystem/TAR/zh/zh | | {{#ifexist: BackupYourSystem/TAR/zh/zh | | {{#ifeq: {{#titleparts:BackupYourSystem/TAR/zh|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:BackupYourSystem/TAR/zh|1|-1|}} | zh | | }}
- title
译注:文章已经经过改动。
用TAR来备份系统
这篇文章已经被改动过了,以便更好地刊登到wiki上。完整的版本可以看这里the original forum post. |
如果你没有正确使用程序来备份,那你的资料可能就会被你抹去了。所以请在读完后再动手 |
介绍
这篇文章是HOWTO系列中 备份系统 的一部分.
This guide to backup your system using tar to create compressed archives is based upon a post from the Ubuntu Community Forums written by Heliode. See the original forum thread for discussion: http://www.ubuntuforums.org/showthread.php?t=35087 . |
为备份系统做准备
Just a quick note. You are about to back up your entire system. Don't forget to empty your Wastebasket, remove any unwanted files in your /home directory, and cleanup your desktop. |
- Depending on why you're backing up, you might want to:
- Delete all your emails
- Clear your browser search history
- Wipe your saved browser personal details
If you are not worried about the security concerns, this step is not necessary. Many users explicitly want backups of their email and browser settings. |
- Unmount any external media devices, and remove any CDs/DVDs not needed for the backup process.
- This will lessen the amount of exclusions you need to type later in the process.
Backing up
- Some directories require root or superuser permissions to successfully backup. Gain superuser access by opening a terminal and entering:
sudo -s -H
- Go to the root of your file system:
cd /
We use the file system root in our example, but you use any target destination you want. You can use remote or removable drives as your backup destination. |
- Create a backup of your system:
tar -cvzf /backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys /
- 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
- 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 directories aren't very useful to include.
- Make sure you don't include the file itself, or else you'll get weird results.
- Don't include the /mnt folder if you have other partitions mounted there.
- If you have Partitions in /mnt that require backup, you will need to exclude the folders you do not want backed up.<
>
--exclude=/mnt/<unwanted_partition>
|
- Make sure you don't have anything mounted in /media.
- Remove CDs/DVDs and removable media that you don't need backed up. You can selectively exclude directories in /media if you want removable devices backed up.
- 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 file systems you can use the
--one-file-system
option in addition to or instead of--exclude
. - With the
--one-file-system
option, only the "local" file system is backed up. <
>
The "local" file system is the file system you have specified, not the file systems mounted under it in the file hierarchy. Use df to see which file systems you have mounted.
|
tar -cvzf /backup.tgz --one-file-system --exclude=/lost+found --exclude=/backup.tgz /
- Relax while Tar creates a backup of your system. This make take awhile depending on the amount of data that is being backed up and the speed of your processor. When the process is complete you will have a file named backup.tgz in the root directory of your file system. This file may be burned to a CD/DVD, moved to another partition/drive, or even stored on another machine.
- Files that are bigger than 2GB are not supported by some implementations of ISO9660 and 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
or use a different way to get it onto the DVD. Seeman split
for further information onsplit
. - A possible workaround 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
- 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:
sudo tar --extract --bzip2 --file /dev/hda
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. |
- Another workaround would be to Bzip2 to compress your backup. Bzip2 provides a higher compression ratio at the expense of speed. If compression is important to you, just substitute the
z
in the command withj
, and change the file name to backup.tar.bz2.
That would make the command look like this:
tar -cvpjf /backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /
Backup over a network
- It is possible to use netcat to transfer the backup between computers.
- On the receiving end you'll setup netcat to write the backup file like this:
nc -l -p 1024 > backup.tar.bz2
- Then you pipe the tar command without the
f
flag through netcat on the sending end like this:
tar -cvj <all those other options> / | nc -q 0 <receiving host> 1024
- In the above commands 1024 is just a random port number, anything from 1024 and up should work.
- If all goes well the backup will be piped through the network without touching the file system being read.
- You can also use SSH:
tar zcvf - /home | ssh <backuphost> "( cat > home_bkp.tar.gz )"
- In this example:
- The directory to backup is /home
- The backup destination is home_bkp.tar.gz on the machine called <backuphost>.
- The hyphen before /home tells tar to send output to stdout rather than to a file.
- Adding the 'p' option to tar would preserve file permissions.
Restoring
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! |
For the purpose of this tutorial we will assume your backup file is stored in the file system root. We will also assume that you have already gained superuser access through sudo
.
- Restore your backup:
tar -xvpzf /backup.tgz -C /
- If you used bz2:
tar -xvpjf backup.tar.bz2 -C /
- A brief explanation:
- The x option tells tar to extract the file.
- The -C <directory> option tells tar to change to a specific directory before extracting. " / " in this example.
- The p option preserves all file permissions. This is default action for tar when used by the superuser.
This will overwrite every single file on your partition with the one in the archive. |
- The restoration process may take awhile, depending on the size of the archive and the speed of your computer.
- Once the extraction is complete, re-create the directories which were excluded.
mkdir /proc /lost+found /mnt /sys
- Reboot and everything should be restored to the state of your system when you made the backup.
It may not be exactly the way it was when you made the backup, because files created after the backing up won't be deleted. |
Restoring over a network
- If you used nc to backup to another computer the commands to restore are:
- On the receiving side:
- Mount the disk (if you are running from a LiveCD)and type:
nc -l -p 1024 | tar -xvpjf - -C /mnt/disk
- On the sender side, the side that has the backup file:
cat backup.tar.bz2 | nc -q 0 <receiving host> 1024
- The - character will tell tar to accept the input from stdin, the pipe.
- The backup file will be expanded without being saved on the disk on the receiver, like when the backup was made.
"-xvpjf
is for a .bz2 file, changej
toz
if you used a tar.gz backup.
Reformatted Partitions
- If you had to format partitions, update the /etc/fstab and /boot/grub/menu.lst files after restoring the backup.
- Mount the reformatted partitions on a LiveCD.
- Open a terminal and type
blkid
- Making note of the UUIDs, edit the /etc/fstab and /boot/grub/menu.lst files in the restored root partition.
sudo nano /mnt/disk/etc/fstab
sudo nano /mnt/disk/boot/grub/menu.lst
Change the UUIDs to match the results of yourblkid
command.
Restoring GRUB
- In most cases restoring GRUB should not be necessary.
- If when you boot the system you are left on a grub shell, just do this
find /boot/grub/stage1
root (hd?,?)
setup (hd?)
substitute the ?
with the results of your find
command.
press esc to restart the system.