6.1 tar:打包备份
tar命令
tar命令选项
备份站点目录html
[root@cs6 ~]# mkdir -p /var/www/html/oldboy/test
[root@cs6 ~]# touch /var/www/html/{1..10}.html
[root@cs6 ~]# ls /var/www/html/
10.html 1.html 2.html 3.html 4.html 5.html 6.html 7.html 8.html 9.html oldboy
[root@cs6 ~]# cd /var/www/
[root@cs6 www]# ls
html
[root@cs6 www]# tar zcvf www.tar.gz ./html
./html/
./html/4.html
./html/7.html
./html/oldboy/
./html/oldboy/test/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
[root@cs6 www]# ll -h www.tar.gz
-rw-r--r--. 1 root root 255 May 12 18:20 www.tar.gz [root@cs6 www]# tar ztvf www.tar.gz #<一使用选项-t不解压就可以查看压缩包的内容,选项v可以显示文件的属性。
drwxr-xr-x root/root 0 2019-05-12 18:19 ./html/
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/4.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/7.html
drwxr-xr-x root/root 0 2019-05-12 18:19 ./html/oldboy/
drwxr-xr-x root/root 0 2019-05-12 18:19 ./html/oldboy/test/
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/9.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/2.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/5.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/3.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/6.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/10.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/1.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/8.html [root@cs6 www]# tar ztf www.tar.gz #<==省略v选项。
./html/
./html/4.html
./html/7.html
./html/oldboy/
./html/oldboy/test/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
[root@cs6 www]# tar tf www.tar.gz #<=如果不指定z选项,那么tar命令也会自动判断压缩包的类型,自动调用gzip命令。
./html/
./html/4.html
./html/7.html
./html/oldboy/
./html/oldboy/test/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
解开压缩包
[root@cs6 www]# tar zxvf www.tar.gz -C /tmp/
./html/
./html/4.html
./html/7.html
./html/oldboy/
./html/oldboy/test/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
[root@cs6 www]# ls /tmp/html/
10.html 1.html 2.html 3.html 4.html 5.html 6.html 7.html 8.html 9.html oldboy
[root@cs6 www]# tar xf www.tar.gz -C /tmp/ #去掉v选项也可以,只要涉及解压的操作,tar命令都能自动识别压缩包的质缩类型,但是压缩时必须要加上z选项。
排除打包
[root@cs6 www]# tar zcvf www.tar.gz ./html/ --exclude=html/oldboy/test
./html/ #<==test目录结尾不要加/,否则不会成功。
./html/4.html
./html/7.html
./html/oldboy/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
[root@cs6 www]# tar zcvf www.tar.gz ./html/ --exclude=html/oldboy/test --exclude=html/oldboy
./html/ #<-=排除2个以上目录的方法:并列使用多个--exclude。
./html/4.html
./html/7.html
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
排除多个文件打包参数-X
[root@cs6 www]# cat list.txt
10.html
8.html
1.html
7.html
5.html
[root@cs6 www]# tar zcvfX paichu.tar.gz list.txt ./html/
./html/
./html/4.html
./html/oldboy/
./html/oldboy/test/
./html/9.html
./html/2.html
./html/3.html
./html/6.html
打包链接文件
[root@cs6 www]# cd /etc/
[root@cs6 etc]# tar zcf local.tar.gz ./rc.local
[root@cs6 etc]# tar tvf local.tar.gz
lrwxrwxrwx root/root 0 2019-05-05 23:11 ./rc.local -> rc.d/rc.local
[root@cs6 etc]# tar zcfh local_h.tar.gz ./rc.local
[root@cs6 etc]# tar tvf local_h.tar.gz
-rwxr-xr-x root/root 220 2018-06-20 00:12 ./rc.local
解决tar使用-exclude 选项时遇到的问题。
[root@cs6 www]# tar zcvf www.tar.gz ./html/ --exclude=/var/www/html/oldboy/test
./html/ #<==打包路径为相对路径,--exclude的路径为绝对路径。
./html/4.html
./html/7.html
./html/oldboy/
./html/oldboy/test/ #<==没有成功排除。
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
[root@cs6 www]# tar zcvf www.tar.gz ./html/ --exclude=html/oldboy/test
./html/ #<==打包路径为相对路径,--exclude的路径为相对路径。
./html/4.html
./html/7.html
./html/oldboy/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html [root@cs6 www]# tar zcvf www.tar.gz ./html/ --exclude=oldboy/test
./html/ #<==--exclude的相对路径去掉html也可以。
./html/4.html
./html/7.html
./html/oldboy/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html [root@cs6 www]# tar zcvf www.tar.gz /var/www/html/ --exclude=/var/www/html/oldboy/test
tar: Removing leading `/' from member names #<==打包路径为绝对路径,--exclude的路径为绝对路径。
/var/www/html/
/var/www/html/4.html
/var/www/html/7.html
/var/www/html/oldboy/
/var/www/html/9.html
/var/www/html/2.html
/var/www/html/5.html
/var/www/html/3.html
/var/www/html/6.html
/var/www/html/10.html
/var/www/html/1.html
/var/www/html/8.html [root@cs6 www]# tar zcvf www.tar.gz /var/www/html/ --exclude=html/oldboy/test
tar: Removing leading `/' from member names #<==打包路径为绝对路径,--exclude的路径为相对路径。
/var/www/html/
/var/www/html/4.html
/var/www/html/7.html
/var/www/html/oldboy/
/var/www/html/9.html
/var/www/html/2.html
/var/www/html/5.html
/var/www/html/3.html
/var/www/html/6.html
/var/www/html/10.html
/var/www/html/1.html
/var/www/html/8.html [root@cs6 www]# tar zcvf www.tar.gz /var/www/html/ --exclude=oldboy/test
tar: Removing leading `/' from member names #<== --exclude的相对路径去择html也可以。
/var/www/html/
/var/www/html/4.html
/var/www/html/7.html
/var/www/html/oldboy/
/var/www/html/9.html
/var/www/html/2.html
/var/www/html/5.html
/var/www/html/3.html
/var/www/html/6.html
/var/www/html/10.html
/var/www/html/1.html
/var/www/html/8.html
打包/etc目录下所有的普通文件
[root@cs6 /]# ls etc
adjtime DIR_COLORS init.d motd [root@cs6 /]# tar zcvf /tmp/etc.tar.gz `find etc/ -type f` #<==使用find找到所有的普通文件,在tar上命令语句中嵌套一个反引号包含的find命令语句。
[root@cs6 /]# ll -h /tmp/etc.tar.gz
-rw-r--r--. 1 root root 8.7M May 12 18:46 /tmp/etc.tar.gz
6.1 tar:打包备份的更多相关文章
- MySQL数据物理备份之tar打包备份
复制数据文件方式,可以使用cp或tar 1.停止服务 [root@localhost mysql]# systemctl stop mysqld [root@localhost mysql]# net ...
- linux下rsync和tar增量备份梳理
前面总结过一篇全量备份/增量备份/差异备份说明,下面介绍下linux下rsync和tar两种增量备份的操作记录: 1)rsync备份 rsync由于本身的特性,在第一次rsync备份后,以后每次都只是 ...
- 烂泥:CentOS命令学习之tar打包与解压
本文由秀依林枫提供友情赞助,首发于烂泥行天下. tar命令一般是做打包和解压使用,有关tar命令的使用.我们可以通过帮助文档进行查看,如下: tar –help man tar tar有几个比较重要的 ...
- Linux tar打包命令
Linux tar打包命令: 范例一:将整个 /etc 目录下的文件全部打包成为 /tmp/etc.tar [root@linux ~]# tar -cvf /tmp/etc.tar /etc < ...
- linux中tar 打包指定路径文件
linux中tar打包指定路径文件www.111cn.net 编辑:yahoo 来源:转载在linux系统中打包与解压文件我都可以使用tar命令来解决,只要使用不同的参数就可以实现不同的需要了,下面来 ...
- tar打包如何不打包某一个文件夹(排除某些文件夹)
tar打包如何不打包某一个文件夹(排除某些文件夹) 问题描述: 最近想备份一下Tomcat运行的的功能文件,以防特殊情况的发生.但是在实际操作的过程中发现,可能是由于Unix/Linux版本太老的原因 ...
- tar --打包和压缩
tar 参考链接 作用:为linux的文件和目录创建档案,也可以在档案中改变文件,或者向档案中加入新的文件即用来压缩和解压文件.tar本身不具有压缩功能.他是调用压缩功能实现的 语法:tar[必要参 ...
- tar打包时的排除选项
1. 在命令行排除文件时,用 --exclude, 可以用多个--exclude . 可以用=号,也可以不用 如 tar -cvf ./aaa.tar ./tvc --exclude ...
- zip压缩工具 tar打包 打包并压缩
6.5 zip压缩工具 6.6 tar打包 6.7 打包并压缩 zip压缩工具 xz,bzip2,gzip都不支持压缩目录 zip可以压缩目录 压缩文件 zip 2.txt.zip 2.txt [ ...
随机推荐
- 如何写好一个 Spring 组件
背景 Spring 框架提供了许多接口,可以使用这些接口来定制化 bean ,而非简单的 getter/setter 或者构造器注入.细翻 Spring Cloud Netflix.Spring Cl ...
- 16. Vue2.4+新增属性$attrs
vm.$attrs简介 首先我们来看下vue官方对vm.$attrs的介绍: 包含了父作用域中不作为 prop 被识别 (且获取) 的特性绑定 (class 和 style 除外).当一个组件没有声明 ...
- Java JFR 民间指南 - 事件详解 - jdk.ObjectAllocationSample
对象分配采样:jdk.ObjectAllocationSample 引入版本:Java 16 相关 ISSUE:Introduce JFR Event Throttling and new jdk.O ...
- matlab结构体、数组和单元数组类型的创建
matlab结构体.数组和单元数组类型的创建 @ 目录 matlab结构体.数组和单元数组类型的创建 matlab结构体类型 数组类型 单元数组类型 matlab结构体类型 通过字段赋值创建结构体 创 ...
- 1.4.15- HTML标签之链接标签
代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- 12- APP接口测试以及接口文档的分析
什么是接口? 为什么要做接口测试? 接口测试流程 需求评审 需求分析 接口用例设计 执行测试用例 bug的定位于追踪 接口文档分析 接口文档分析:开发 内容: 1.接口名称 2.接口地址 3.支持方式 ...
- 【Scrapy(一)】 Scrapy爬虫的基础执行流程
安装scrapy模块 : pip install scrapy 创建scrapy项目 1.scrapy startprojecty 项目名称 注意:如果创建失败,可以先卸载原有的scrapy模块, ...
- 本地使用apache设置绑定多个域名
Apache开启了使用虚拟主机的功能: 打开Apache安装目录下conf/httpd.conf文件,找到 #LoadModule vhost_alias_module modules/mod_vho ...
- Linux系统调用表
Linux系统调用表 记录下来,免得到处找 32位 int 0x80 %eax Name Source %ebx %ecx %edx %esx %edi 1 sys_exit kernel/exit. ...
- thinkphp 中区块block和模板继承extend用法举例
1.介绍 模板继承其实并不难理解,就好比类的继承一样,模板也可以定义一个基础模板(或者是布局),并且其中定义相关的区块(block),然后继承(extend)该基础模板的子模板中就可以对基础模板中定义 ...