<script type="text/javascript"><!-- google_ad_client = "pub-5143338080895292"; /* 728x90, created 4/10/08 */ google_ad_slot = "6675122003"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

The quick way to CPIO

2008-05-15 12:44:56 / 个人分类:OpenBSD SysAdmin

<scrīpt type="text/javascrīpt"><!--
google_ad_client = "pub-5143338080895292";
/* 728x90, created 4/10/08 */
google_ad_slot = "6675122003";
google_ad_width = 728;
google_ad_height = 90;
//-->
</scrīpt>
<scrīpt type="text/javascrīpt"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</scrīpt>

Like the TAR command, CPIO is used to backup or archive files and directories.

The difference is that tar by default backup file to a tape device and backup all of a specified directory, whereas cpio by default archive only the files you tell it to using command line arguments. That’s why it’s always (almost) used with other command to do backup/archive.

To start with, backup a directory under /home/acheng/www:

#cd /home/acheng/www

#find -d . | cpio -ovF ../wwwbak.cpio

When using the find utility with cpio, it is always a good idea to include either the d or the depth switch. This switch prevented permissions from interfering with a backup. When using this switch, either put -d right after the word find and before the directory to search (in this case, “.“), or put the word -depth after the directory to search, like so:

#find . -depth -print | cpio -ov > backup.cpio

To view the contents of a cpio archive without extracting, use:

# cpio -it < ../wwwbak.cpio

To extract, use:

#mkdir ../restore;cd ../restore

#cpio -ivd < ../wwwbak.cpio

Note the d switch, it tell cpio to create any dir when necessary. otherwise it’ll compain not being able to find the dir to restore to.

You can also use -p switch to let cpio emulate what cp can do with a directory or file, that is to copy them over to a different place.

The benefit of using cpio instead of cp is that you can fine tune the files/dirs you want to copy with utilities like FIND and you can reserve a file’s create time/modified time, plus you can reserve/change a file’s ownership at wish.

Let’s say you want to backup the www dir to /tmp:

#cd /home/acheng/www

#find -d . | cpio -pvd /tmp

Or change the ownership of all copied files to user alan:

#find -d . | cpio -pvd -R alan /tmp

To reserve all original time of these files, use:

#find -d . | cpio -pvdam -R alan /tmp

** use “man cpio” for more information and options with cpio

–end–



TAG: MySQL OpenBSD Database

我来说两句

-5 -3 -1 - +1 +3 +5

Open Toolbar