个人工具
119.28.94.63
该IP地址的讨论
登录
查看“UbuntuHelp:BackupYourSystem/TAR/zh”的源代码 - Ubuntu中文
UbuntuHelp
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“UbuntuHelp:BackupYourSystem/TAR/zh”的源代码
来自Ubuntu中文
←
UbuntuHelp:BackupYourSystem/TAR/zh
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
=== Backing up === https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=terminal.png * Some directories require root or superuser permissions to successfully backup. Gain superuser access by opening a [[UbuntuHelp:UsingTheTerminal|terminal]] and entering:<pre><nowiki> sudo -s -H </nowiki></pre> * Go to the root of your file system: <pre><nowiki> cd / </nowiki></pre> {|border="1" cellspacing="0" |https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconHint2.png 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:<pre><nowiki> tar -cvzf /backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys / </nowiki></pre> * https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=info.png 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.<<BR>> {|border="1" cellspacing="0" | https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png <code><nowiki>--exclude=/mnt/<unwanted_partition></nowiki></code> |} * 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 <code><nowiki>--one-file-system</nowiki></code> option in addition to or instead of <code><nowiki>--exclude</nowiki></code>. * With the <code><nowiki>--one-file-system</nowiki></code> option, only the "local" file system is backed up. <<BR>> {|border="1" cellspacing="0" | https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=info.png The "local" file system is the file system you have specified, not the file systems mounted under it in the file hierarchy. Use <code><nowiki>df</nowiki></code> to see which file systems you have mounted. |} https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png <pre><nowiki> tar -cvzf /backup.tgz --one-file-system --exclude=/lost+found --exclude=/backup.tgz / </nowiki></pre> * 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. * https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=stop.png 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 <code><nowiki>split</nowiki></code> or use a different way to get it onto the DVD. See <code><nowiki>man split</nowiki></code> for further information on <code><nowiki>split</nowiki></code>. * A possible workaround is the following:<pre><nowiki> sudo tar --create --bzip2 --exclude /tmp --one-file-system --sparse / | growisofs -use-the-force-luke -Z /dev/hda=/proc/self/fd/0 </nowiki></pre> * Note that this only backs up one file system. You might want to use <code><nowiki>--exclude</nowiki></code> instead of <code><nowiki>--one-file-system</nowiki></code> 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: <pre><nowiki> sudo tar --extract --bzip2 --file /dev/hda </nowiki></pre> {|border="1" cellspacing="0" | https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconHint2.png 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 <code><nowiki>z</nowiki></code> in the command with <code><nowiki>j</nowiki></code>, and change the file name to ''backup.tar.bz2''. That would make the command look like this: <pre><nowiki> tar -cvpjf /backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys / </nowiki></pre> ==== 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:<pre><nowiki> nc -l -p 1024 > backup.tar.bz2 </nowiki></pre> * Then you pipe the tar command without the <code><nowiki>f</nowiki></code> flag through netcat on the sending end like this:<pre><nowiki> tar -cvj <all those other options> / | nc -q 0 <receiving host> 1024 </nowiki></pre> * 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: <pre><nowiki> tar zcvf - /home | ssh <backuphost> "( cat > home_bkp.tar.gz )" </nowiki></pre> * https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=info.png 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.
返回至
UbuntuHelp:BackupYourSystem/TAR/zh
。