Shell/Bash在线运行

所属目录
点击了解高性能代码运行API
运行结果
教程手册
代码仓库
极速运行
交互输入
极速运行模式,更高效的运行,点击编辑器上方的运行按钮即刻体验吧。
以下是用户最新保存的代码
# 命令替换 有两种方法: - 方法一:`command` - 方法二:$(command) 总结: - ``和$()两者是等价的,但推荐初学者使用$(),易于掌握;缺点是极少数UNIX可能不支持,但``都是支持的 - $(())主要用来进行整数运算,包括加减乘除,引用变量前面可以加$,也可以不加$ 发布于:2023-03-17 21:48 awk的for循环和二维字典和printf实现二维数据表倒置 发布于:2023-03-15 23:34 # 变量替换 ## 字符串处理 ### 字符长度 1. ${#string} 2. `expr length "$string"` ### 获取字符串索引位置 1. expr index "$string" substr ### 获取子串长度 1. expr match "$string" substr ### 抽取子串 方法一: 1. ${string:position} 2. ${string:position:length} 3. ${string: -position} 或者 ${string:(position)} 方法二: 1. expr substr $string $position $length 注意:使用expr,索引计数是从1开始计算;使用${string:position},索引计数是从0开始计数 发布于:2023-03-17 21:33 for 循环用法 发布于:2023-03-15 03:47 测试测试测试测试测试测试测试 发布于:2023-03-14 10:48 #echo,xargs,sort,uniq,awk命令实现word.txt统计word次数 发布于:2023-03-14 10:47 工业互联网日报 发布于:2023-03-06 12:52 初次使用shell测试 发布于:2023-03-04 21:31 while 循环123 发布于:2023-03-01 22:48 检测两台服务器指定目录下的文件一致性 发布于:2023-02-27 21:22 增加新的判断条件并且兼容没有设置过判断参数的项目 发布于:2023-02-24 16:03 REDIS监控 发布于:2023-02-27 09:18 shell脚本1 发布于:2023-02-21 15:08 测试shell 发布于:2023-01-31 09:46 支持库安装 发布于:2022-12-29 12:15 测试软件服务是否安装并确认是否安装 发布于:2022-12-28 14:56 自定义函数 发布于:2022-12-27 10:49 read读取控制台输入 read (选项)(参数) 发布于:2022-12-27 09:14 while循环 while [ 条件判断式 ] do 程序 done 执行结果不对,为啥呢 发布于:2022-12-26 17:49 for循环 语法二 for 变量 in 值1 值2 值3... do 程序 done 发布于:2022-12-26 17:30 for循环 发布于:2022-12-26 17:16 shell脚本测试! 发布于:2022-12-20 17:25 for字符写三行值 发布于:2022-12-19 10:49 求最大值。 发布于:2022-12-19 10:48 Shell 基础知识 发布于:2022-12-06 00:41 【Shell】测试read功能,注意两次的输入要有回车 发布于:2022-12-01 20:15 【Shell】此段代码为shell if else测试代码 发布于:2022-12-01 20:16 the number of dirctary is 13 the number of file is 16 发布于:2022-11-30 00:27 bash-测试表清理 发布于:2022-11-28 18:09 设计一个任意输入一个数,判断这个数是不是质数 发布于:2022-11-26 18:02 shell判断解压 发布于:2022-11-24 16:49 九九乘法表 发布于:2022-11-07 17:39 字符类型判断 发布于:2022-11-07 21:45 12 编写shell脚本,执行后,打印一行提示“Please input a number.”逐次打印用户输入数值,直到用户输入“end”为止。 发布于:2022-10-24 21:42 程序建立三个以输入日期为名称的文件. 发布于:2022-07-12 15:19 用户输入姓氏和名字,系统输出姓名 发布于:2022-07-12 15:01 相隔某数倍数进行打印 发布于:2022-05-25 10:21 工作测试代码 发布于:2022-05-16 14:10 shell基础语法 发布于:2022-04-11 18:29 shell脚本 发布于:2022-01-20 15:56 sssasdfsad asdf asdfa 发布于:2021-10-08 17:10 在线Shell体验 发布于:2021-08-11 09:50 在线shell体验 发布于:2021-08-11 09:45 #输入一个数字,并显示出来。 发布于:2021-08-05 17:05 r_daily_new_clue_d.sh 发布于:2021-07-22 20:34 shell脚本测试 发布于:2021-07-20 20:02 查找局域网内可ssh登录的主机(22端口) 发布于:2021-07-14 18:03 dns setting for macOS 发布于:2021-06-22 14:54 不用date编写计算时间的脚本 发布于:2021-05-23 14:11 第一个shell程序 发布于:2021-05-09 16:12 [更多]
显示目录

restore 命令-恢复dump操作的数据



restore 命令

restore 命令是 dump 命令的配套命令,dump 命令是用来备份分区和数据的,而 restore 命令是用来恢复数据的。

基本格式

[root@localhost ~]# restore [模式选项] [-f]

-f 选项用于指定备份文件的文件名;restore 命令常用的模式有以下 4 种,这 4 种模式不能混用:

-C: 比较备份数据和实际数据的变化。
实际数据中现有数据发生变化,这个选项能检测到这个变化。
但实际数据中新增了数据,这个选项不能检测到变化的。
-i: 进入交互模式,手工选择需要恢复的文件;
-t: 查看模式,用于查看备份文件中拥有哪些数据;
-r: 还原模式,用于数据还原;

示例

比较备份数据和实际数据的变化。

这里大家需要注意,数据比较只有在原有数据减少或发生变化时才能检测到变化,而新增的数据是不会被检测到的。命令如下:

[root@localhost ~]# touch /boot/abc
#在/boot/目录中新建abc文件
[root@localhost ~]# restore -C -f /root/boot.bak.bz2
Dump tape is compressed.
Dump date:Wed Jun 5 08:20:02 2013
Dumped from:the epoch
Level 0 dump of /boot on localhost:/dev/sda1
Label:none
filesys = /boot
#restore检测,没发现任何变化(备份数据在备份时没有abc文件,restore命令是不能识别新建文件的)
[root@localhost ~]# mv /boot/vmlinuz-2.6.32-279.el6.i686 /boot/vmlinuz-2.6.32-279.el6.i686.bak
#把/boot/目录中的内核镜像文件改一个名字
[root@localhost ~]# restore -C -f /root/boot.bak.bz2
Dump tape is compressed.
Dump date:Wed Jun 5 08:20:02 2013
Dumped from:the epoch
Level 0 dump of /boot on localhost:/dev/sda1
Label:none
filesys = /boot
restore:unable to stat ./vmlinuz-2.6.32-279.el6.i686:No such file or directory Some files were modified! 1 compare errors
#restore发现内核镜像文件丢失

这个实验比较危险,一定要记得把内核镜像文件的名字改回来,否则一旦重启,系统就会无法正常启动。

[root@localhost ~]# mv/boot/vmlinuz-2.6.32-279.el6.i686.bak/boot/vmlinuz2.6.32-279.el6.i686

查看模式

这种模式比较简单,就是查看备份文件中到底包含什么内容。命令如下:

[root@localhost ~]# restore -t -f boot.bak.bz2
Dump tape is compressed.
#备份数据是压缩的
Dump date:Wed Jun 5 08:20:02 2013
#数据备份时间
Dumped from:the epoch
Level 0 dump of /boot on localhost:/dev/sda1
#备份等级
Label:none
#分区的卷标,没有设定卷标
2.
11 ./lost+found
12 ./grub
24 ./grub/grub.conf
13 ./grub/splash.xpm.gz
…省略部分输出…

还原模式

restore 命令的还原模式既可以用于还原整个分区,也可以用于还原文件或目录。命令格式是一样的,不过要注意,如果要还原增量备份的数据,则一定要先还原完全备份的数据。命令如下:

#还原boot.bak.bz2分区备份
#先还原完全备份的数据
[root@localhost ~]# mkdir boot.test
#建立准备解压缩的目录。当然,如果这个目录是我新建的分区,就可以直接把数据恢复到分区中
[root@localhost ~]# cd boot.test/
#进入解压缩目录
[root@localhost boot.test]# restore -r -f /root/boot.bak.bz2
Dump tape is compressed.
#备份数据是压缩数据
#解压缩
[root@localhost boot.test]#ll
#查看一下解压缩的文件
总用量21300
-rw-r--r--. 1 root root 106611 6月 22 2012 config-2.6.32-279.el6.i686 drwxr-xr-x. 3 root root 4096 4 月 10 21:47 efi drwxr-xr-x. 2 root root 4096 4 月 10 21:49 grub
-rw-r--r--. 1 root root 14708399 4 月 10 21:49 initrara£s-2.6.32-279.el6.i686.img
drwx------. 2 root root 4096 4 月 10 21:44 lost+found
-rw-------. 1 root root 47504 6 月 5 09:44 restoresymtable
-rw-r--r--. 1 root root 175903 6 月 22 2012 symvers-2.6.32-279.el6.i686.gz
-rw-r--r--. 1 root root 1846041 6 月 22 2012 System.map-2.6.32-279.el6.i686
-rw-r--r--. 1 root root 1048576 6 月 5 02:38 test
-rwxr-xr-x. 1 root root 3856608 6 月 22 2012 vmlinuz-2.6.32-279.el6.i686
#再还原增量备份的数据
[root@localhost boot.test]# restore -r -f /root/boot.bakl.bz2
Dump tape is compressed.
#恢复增量备份的数据
[root@localhost boot.test]# ll
总用量21328
-rw-r--r--. 1 root root 106611 6 月 22 2012 config-2.6.32-279.el6.i686
drwxr-xr-x. 3 root root 4096 4 月 10 21:47 efi
drwxr-xr-x. 2 root root 4096 4 月 10 21:49 grub
-rw-r--r--. 1 root root 14708399 4 月 10 21:49 initramfs-2.6.32-279.eX6.i686.img
-rw-r--r--. 1 root root 24772 6 月 5 08:20 install. log
#增量备份的install.log文件被恢复了
drwx------. 2 root root 4096 4 月 10 21:44 lost+found
-rw-------. 1 root root 47552 6 月 5 09:57 restoresymtable
-rw-r--r--. 1 root root 175903 6 月 22 2012 symvers-2.6.32-279.el6.i686.gz
-rw-r--r--. 1 root root 1846041 6 月 22 2012 System.map-2.6.32-279.el6.i686
-rw-r--r--. 1 root root 1048576 6 月 5 02:38 test
-rwxr-xr-x. 1 root root 3856608 6月  22 2012 vmlinuz-2.6.32-279.el6.i686

还原/etc/目录的备份etc.dump.bz2,其还原方法完全一样。命令如下:

[root@localhost ~]# restore -r -f etc.dump.bz2
Dump tape is compressed.
#还原etc.dump.bz2备份
[root@localhost ~]# ll -d /root/etc
drwxr-xr-x.103 root root 12288 6月 5 07:45 /root/etc
#在root下生成了etc目录,里面的数据和/etc/目录中的数据完全一致
由JSRUN为你提供的Shell/Bash在线运行、在线编译工具
        JSRUN提供的Shell/Bash 在线运行,Shell/Bash 在线运行工具,基于linux操作系统环境提供线上编译和线上运行,具有运行快速,运行结果与常用开发、生产环境保持一致的特点。