一般情况下打包文件时,如果直接打包软连接会导致打包失败,即没有将要打包的内容打包进去,这里提供tar打包参数-h
[[email protected] ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Nov 24 00:45 /etc/rc.local -> rc.d/rc.local
[[email protected] ~]# tar czf tar.gz /etc/rc.local
tar: Removing leading `/‘ from member names
[[email protected] ~]# ll
[[email protected] ~]# sz tar.gz
rz
Starting zmodem transfer. Press Ctrl+C to cancel.
100% 117 bytes 117 bytes/s 00:00:01 0 Errors
[[email protected] ~]#
发现打包结果并没有将/etc/rc.local下的内容打包进来
所以这里用-h参数
[[email protected] ~]# tar czfh rc.local.tar.gz /etc/rc.local
tar: Removing leading `/‘ from member names
[[email protected] ~]# ll
total 84
-rw-------. 1 root root 1508 Nov 24 00:48 anaconda-ks.cfg
drwxr-xr-x. 5 root root 4096 Jun 10 2015 fabric-scripts
-rw-r--r--. 1 root root 17062 Dec 28 10:03 fabric-scripts.tar.gz
-rw-r--r--. 1 root root 33502 Nov 24 00:48 install.log
drwxr-xr-x. 2 root root 4096 Apr 7 15:08 logs
drwxr-xr-x. 3 root root 4096 Mar 23 10:35 mysql-sql
-rw-r--r--. 1 root root 415 Apr 12 16:42 rc.local.tar.gz
-rw-r--r--. 1 root root 117 Apr 12 16:31 tar.gz
[[email protected] ~]# sz rc.local.tar.gz
rz
Starting zmodem transfer. Press Ctrl+C to cancel.
100% 415 bytes 415 bytes/s 00:00:01 0 Errors
[[email protected] ~]#
[[email protected] ~]# tar xf rc.local.tar.gz
[[email protected] ~]# ll
-rw-r--r--. 1 root root 415 Apr 12 16:42 rc.local.tar.gz
-rw-r--r--. 1 root root 117 Apr 12 16:31 tar.gz
[[email protected] ~]# cd etc/
[[email protected] etc]# ll
total 4
-rwxr-xr-x. 1 root root 420 Mar 8 14:36 rc.local
[[email protected] etc]# cat rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don‘t
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
#startup Openvpn on boot
/usr/local/sbin/openvpn --config /etc/openvpn/product.server.conf &
#add a iptables ruler
/sbin/iptables -t nat -I POSTROUTING -s 10.8.0.0/255.255.255.0 -o eth0 -j MASQUERADE
[[email protected] etc]#
至此,用tar打包软连接实际目录下内容操作成功