Linux基础文件打包
2024-09-01 03:28:34
一、打包与解压
(一)、打包压缩
[root@linux ~]# tar -czf etc1.tar.gz /etc //-z 调用gzip
[root@linux ~]# tar -cjf etc2.tar.bz2 /etc //-j 调用bzip2
[root@linux ~]# tar -cJf etc3.tar.xz /etc //-J 调用xz
[root@linux ~]# ll -h etc*
-rw-r--r--. root root 8.7M 3月 : etc1.tar.gz
-rw-r--r--. root root 7.5M 3月 : etc2.tar.bz2
-rw-r--r--. root root 4.8M 3月 : etc3.tar.xz
(二)、解压、解包
[root@linux ~]# tar -tf sys.tar.xz
[root@linux ~]# tar -xzvf etc1.tar.gz
[root@linux ~]# tar -xvf etc1.tar.gz //无需指定解压工具,tar会自动判断
[root@linux ~]# tar -xvf etc2.tar.bz2 -C /tmp //-C重定向到//tmp目录
[root@linux ~]# tar xf etc3.tar.xz
(三)、解压ZIP
[root@linux ~]# unzip xxx.zip
二、案例
(一)、案例1:mysql物理备份及恢复
[root@localhost ~]# tar -cJf /backup/mysql.tar.xz /var/lib/mysql
[root@localhost ~]# tar -xf /backup/mysql.tar.xz -C /
(二)、 mysql物理备份及恢复
[root@localhost ~]# cd /var/lib/mysql
[root@localhost mysql]# tar -cJf /backup/mysql.tar.xz *
[root@localhost mysql]# tar -xf /backup/mysql.tar.xz -C /var/lib/mysql
(三)案例3:host A /etc (海量小文件)
[root@localhost ~]# tar -czf - /etc |tar -xzf - -C /tmp
(四)、案例4:host A /etc(海量小文件)
常规方法:
[root@localhost ~]# scp -r /etc 172.16.20.21:/tmp
建议方法:
==host B 监听端口==
[root@hostb ~]# systemctl stop firewalld.service
[root@hostb ~]# nc -l |tar -xzf - -C /tmp ==host A ==
[root@localhost ~]# tar -czf - /etc | nc 172.16.20.21
tar: Removing leading `/' from member names
最新文章
- [Git] Git 常用技巧
- 打开FTP服务器上的文件夹时发生错误,请检查是否有权限访问该文件夹
- 【Bootstrap3.0建站笔记三】AspNetPager分页,每一列都可排序
- SqlLite ---.net连接数据库
- js冒泡事件示例
- Android 2014年1月22日
- PHP之路——微信公众号授权获取用户信息
- silverlight .net后台 设置visifire控件图表样式 属性说明
- 处理json中的异常字符
- matlab实现可调节占空比的方波
- yii2 源码分析 model类分析 (五)
- 014_zk路径过滤分析
- css 实现文字提示说明、文字绕图效果
- 目标指定法——S.M.A.R.T.
- linux批量替换文件内容3种方法(perl,sed,shell)
- 批量插入bulkcopy
- BUAA 111 圆有点挤
- laravel注册行为的方法和逻辑
- jstat 使用日志
- progressDialog和子线程模拟显示拷贝进度