个人工具

“UbuntuHelp:BackupYourSystem/TAR/zh”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: Linux ChatIRC Blog Paste Wiki Forum Ubuntu 搜索 UbuntuHelp 讨论 编辑 历史 移动 监视 简体 繁體 导航 首页 社区 当前事件 最近更改 随机页面 帮助 ...)
 
(移除所有页面内容)
第1行: 第1行:
Linux
 
ChatIRC
 
Blog
 
Paste
 
Wiki
 
Forum
 
Ubuntu
 
搜索   
 
UbuntuHelp
 
讨论
 
编辑
 
历史
 
移动
 
监视
 
简体
 
繁體
 
  
 
导航
 
首页
 
社区
 
当前事件
 
最近更改
 
随机页面
 
帮助
 
工具箱
 
链入页面
 
链出更改
 
上传文件
 
特殊页面
 
个人工具
 
Chenfengyuan
 
我的对话页
 
我的参数设置
 
我的监视列表
 
我的贡献
 
退出
 
UbuntuHelp:BackupYourSystem/TAR
 
出自Ubuntu中文
 
文章出处:
 
 
https://help.ubuntu.com/community/BackupYourSystem/TAR
 
点击翻译:
 
 
English
 
 
请不要直接编辑翻译本页,本页将定期与来源同步。
 
title
 
目录
 
[隐藏]
 
1 Backup your system using TAR
 
1.1 Introduction
 
1.2 Preparing for backup
 
1.3 Backing up
 
1.3.1 Backup over a network
 
1.4 Restoring
 
1.4.1 Restoring over a network
 
1.5 Reformatted Partitions
 
1.6 Restoring GRUB
 
1.7 Additional resources
 
[编辑] Backup your system using TAR
 
This wiki article has been edited to meet the needs of wiki users. To view the complete content see the original forum post.
 
Improper usage of any archival program can cause unintended data loss. Please read the entire tutorial before proceeding.
 
[编辑] Introduction
 
 
This page is part of the BackupYourSystem series of Howtos.
 
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 .
 
[编辑] Preparing for backup
 
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 -cvpzf /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. See man split for further information on split.
 
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 with j, 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 sender side, the side that has the backup file:
 
cat backup.tar.bz2 | nc -q 0 <receiving host> 1024
 
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
 
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, change j to z if you used a tar.gz backup.
 
[编辑] Reformatted Partitions
 
If you had to format partitions, update the /etc/fstab file 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 in the restored root partition.
 
 
sudo nano /mnt/disk/etc/fstab
 
Change the UUIDs to match the results of your blkid command.
 
[编辑] Restoring GRUB
 
In most cases restoring GRUB should not be necessary.
 
If you need to reinstall grub GRUB see this page.
 
[编辑] Additional resources
 
"Backing Up Ubuntu"
 
"Wei’s world: HOWTO: backup my Ubuntu"
 
取自"http://wiki.ubuntu.org.cn/UbuntuHelp:BackupYourSystem/TAR"
 
4个分类: 翻译请求 | CategoryBackupRecovery | CategoryCommandLine | UbuntuHelp
 
本页面已经被浏览1,664次。
 
此页由Ubuntu中文用户Wikibot于2008年10月19日 (星期日) 22:03的最后更改。 在Oneleaf的工作基础上。
 
关于Ubuntu中文
 
免责声明
 

2008年11月2日 (日) 11:22的版本