1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > linux如何创建备份文件 如何备份Linux 配置文件

linux如何创建备份文件 如何备份Linux 配置文件

时间:2019-09-26 17:25:09

相关推荐

linux如何创建备份文件 如何备份Linux 配置文件

如何备份Linux配置文件

文件备份是服务器安全最重要的一个环节,下面小编介绍使用Git工具来备份Linux配置文件。

一、安装Git

[root@localhost ~]# yum install git

检查Git版本

[root@localhost ~]# git --version

git version 1.8.3.1

[root@localhost ~]#

设置初始参数

将如下命令中的用户名,邮件替换成你自己的。

[root@localhost network-scripts]# git config --global user.name "your_user_name"

[root@localhost network-scripts]# git config --global user.email "your_email"

二、现在初始化Git数据库

因为我准备备份网络配置文件,所以我只需要在网络配置文件的目录初始化Git数据库。

[root@localhost ~]# cd /etc/sysconfig/network-scripts

[root@localhost network-scripts]# git init

Initialized empty Git repository in /etc/sysconfig/network-scripts/.git/

[root@localhost network-scripts]#

命令行输入 ls -a , 那么我们可以看到,“.git” 文件夹被创建了。

三、使用下面的命令进行备份

[root@localhost network-scripts]# git add ifcfg-enp0s3

[root@localhost network-scripts]#

[root@localhost network-scripts]# git commit ifcfg-enp0s3

[master (root-commit) 1269758] Changes on 26 Oct

1 file changed, 16 insertions(+)

create mode 100644 ifcfg-enp0s3

[root@localhost network-scripts]#

当我们执行第二个命令的时候,它会要求你输入像 “Changes on 26 Oct ” 这样的备注,然后保存文件。

使用下面的命令查看 git 日志

[root@localhost network-scripts]# git log

commit 1269758e5f5b2fa3e0ad1fe507abaf73b646a33d

Author: Pradeep Date: Mon Oct 26 00:03:08 -0400

Changes on 26 Oct

[root@localhost network-scripts]#

注:尝试在“ifcfg-enp0s3”文件中插入一些无用字符

四、从Git数据库恢复网络配置文件

[root@localhost network-scripts]# git reset --hard 1269758e5f5b2fa3e0ad1fe507abaf73b646a33d

HEAD is now at 1269758 Changes on 26 Oct

[root@localhost network-scripts]#

使用与上边相同的 git id,你安装的不同,git 的 id 也不同。

验证从 git 数据库恢复的文件是否正确。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。