1.1 概述
维护Linux系统过程中,我们经常会修改配置文件。经验丰富的师傅们,在修改配置文件前,都会备份该文件,那么如何快速、高效的备份配置文件呢?
本期文章结合具体的实践操作,向各位小伙伴总结分享关于Linux系统备份配置文件地最佳实践。
1.2 实践目标
1、 备份Linux系统网卡配置文件,备份的配置文件名“含具体的时刻”;
2、 删除备份的配置文件
Tips:Linux系统版本是CentOS 8
1.3 最佳实践操作
1.3.1 备份前的准备
查看网卡名称,如下所示,网卡的名称是ens192;
[root@localhost ~]# ifconfig | grep ens
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
[root@localhost ~]#
查找网卡名称对应配置文件的具体路径,如下所示,网卡的配置文件路径是“/etc/sysconfig/network-scripts/ifcfg-ens192”;
[root@localhost ~]# find /etc/ -type f -name *ens192*
/etc/sysconfig/network-scripts/ifcfg-ens192
[root@localhost ~]#
1.3.2 备份方案1
[root@localhost ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens192 /etc/sysconfig/network-scripts/"ifcfg-ens192_backup_$(date '+%F-%T')"
[root@localhost ~]#
[root@localhost ~]# find /etc/ -type f -name *ens192*
/etc/sysconfig/network-scripts/ifcfg-ens192
/etc/sysconfig/network-scripts/ifcfg-ens192_backup_2023-07-25-10:21:42
[root@localhost ~]#
1.3.3 备份方案2
[root@localhost ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens192 /etc/sysconfig/network-scripts/"ifcfg-ens192_backup_`date '+%F-%T'`"
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# find /etc/ -type f -name *ens192*
/etc/sysconfig/network-scripts/ifcfg-ens192
/etc/sysconfig/network-scripts/ifcfg-ens192_backup_2023-07-25-10:21:42
/etc/sysconfig/network-scripts/ifcfg-ens192_backup_2023-07-25-10:22:52
[root@localhost ~]#
1.3.4 备份方案3-推荐
[root@localhost ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens192{,"_backup_$(date '+%F-%T')"}
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# find /etc/ -type f -name *ens192*
/etc/sysconfig/network-scripts/ifcfg-ens192
/etc/sysconfig/network-scripts/ifcfg-ens192_backup_2023-07-25-10:21:42
/etc/sysconfig/network-scripts/ifcfg-ens192_backup_2023-07-25-10:22:52
/etc/sysconfig/network-scripts/ifcfg-ens192_backup_2023-07-25-10:25:06
[root@localhost ~]#
1.3.5 备份方案4-推荐
[root@localhost ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens192{,"_backup_`date '+%F-%T'`"}
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# find /etc/ -type f -name *ens192*
/etc/sysconfig/network-scripts/ifcfg-ens192
/etc/sysconfig/network-scripts/ifcfg-ens192_backup_2023-07-25-10:21:42
/etc/sysconfig/network-scripts/ifcfg-ens192_backup_2023-07-25-10:22:52
/etc/sysconfig/network-scripts/ifcfg-ens192_backup_2023-07-25-10:25:06
/etc/sysconfig/network-scripts/ifcfg-ens192_backup_2023-07-25-10:25:39
[root@localhost ~]#
1.3.6 删除备份的文件
[root@localhost ~]#find /etc/ -type f -name *ens192_* | xargs rm -f
[root@localhost ~]#
[root@localhost ~]#find /etc/ -type f -name *ens192*
/etc/sysconfig/network-scripts/ifcfg-ens192
[root@localhost ~]#
1.4 总结
备份Linux系统网卡配置文件最佳实践操作与配置其它服务的配置文件,操作方式类似,各位师傅们可上手实践验证了。
以上分享,希望各位小伙伴有所收获,欢迎各位点赞收藏和指正。 |