我们在使用Linux服务器的时候,有时候需要备份配置文件。传统的备份方法是复制文件,重命名,在文件末尾插入一些字符。 不过,如果我们使用Git,我们可以很方便的管理配置文件的备份。在本文中,我将演示如何使用Git来实施和管理备份。我用来测试的环境是CentOS7和RHEL7。1.安装Git [root@localhost~]#yuminstallgit 查看Git版本[root@localhost~]#git--versiongitversion1.8.3.1[root@localhost~]# settings初始参数 将以下命令中的用户名和电子邮件替换为您自己的。[root@localhostnetwork-scripts]#gitconfig--globaluser.name"your_user_name"[root@localhostnetwork-scripts]#gitconfig--globaluser.email"your_email" 其次,现在初始化Git数据库 因为我是要备份网络配置文件,所以我只需要在网络配置文件的目录中初始化Git数据库。[root@localhost~]#cd/etc/sysconfig/network-scripts[root@localhostnetwork-scripts]#gitinitInitializedemptygitrepositoryin/etc/sysconfig/network-scripts/.git/[root@localhostnetwork-scripts]# 命令行输入ls-a,我们可以看到“.git”文件夹被创建了。 3.使用以下命令备份[root@localhostnetwork-scripts]#gitaddifcfg-enp0s3[root@localhostnetwork-scripts]#[root@localhostnetwork-scripts]#gitcommitifcfg-enp0s3[master(root-commit)1269758]Changeson26Oct20151filechanged,16insertions(+)createmode100644ifcfg-enp0s3[root@localhostnetwork-scripts]# 当我们执行第二个命令时,它会要求你输入一个注释,比如“Changeson26Oct2015”,然后保存文件。使用以下命令检查git日志[root@localhostnetwork-scripts]#gitlogcommit1269758e5f5b2fa3e0ad1fe507abaf73b646a33dAuthor:Pradeep
