网站首页 > 技术教程 正文
我们使用 Linux 服务器时,有时候需要备份配置文件。传统的备份方法是复制文件,改名,并在文件结尾插入一些字符。
但,如果我们使用 Git ,我们可以很轻松的管理配置文件的备份。在这篇文章中,我将会演示如何使用 Git 来实现备份以及管理备份。我测试所用的环境是 CentOS 7 和 RHEL 7。
一、安装 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 2015
1 file changed, 16 insertions(+)
create mode 100644 ifcfg-enp0s3
[root@localhost network-scripts]#
当我们执行第二个命令的时候,它会要求你输入像 “Changes on 26 Oct 2015” 这样的备注,然后保存文件。
使用下面的命令查看 git 日志
[root@localhost network-scripts]# git log
commit 1269758e5f5b2fa3e0ad1fe507abaf73b646a33d
Author: Pradeep <pradeep@linuxtechi.com> Date: Mon Oct 26 00:03:08 2015 -0400
Changes on 26 Oct 2015
[root@localhost network-scripts]#
注:尝试在 “ifcfg-enp0s3” 文件中插入一些无用字符
四、从 Git 数据库恢复网络配置文件
[root@localhost network-scripts]# git reset --hard 1269758e5f5b2fa3e0ad1fe507abaf73b646a33d
HEAD is now at 1269758 Changes on 26 Oct 2015
[root@localhost network-scripts]#
使用与上边相同的 git id,你安装的不同,git 的 id 也不同。
验证从 git 数据库恢复的文件是否正确。
链接请在原文获取,点击阅读全文~
- 上一篇: Linux 网络配置(CentOS7 && RHEL7)
- 下一篇: 第五章 网络配置
猜你喜欢
- 2025-04-29 Linux中为局域网配置yum源(httpd方式)
- 2025-04-29 linux安装jdk,全局配置,不同用户不同jdk
- 2025-04-29 linux环境JDK配置环境变量
- 2025-04-29 一天一个Linux命令:网络管理(IP 地址配置)
- 2025-04-29 CentOS 8 网络配置实战教程:静态IP、路由与DNS设置
- 2025-04-29 Linux新手入门系列:Linux下jdk安装配置
- 2025-04-29 Linux中安装jdk并配置环境变量
- 2025-04-29 Linux服务器配置DNS解析
- 2025-04-29 linux文件之ssh配置文件的含义与作用
- 2025-04-29 Linux环境变量配置全攻略
你 发表评论:
欢迎- 08-03Linux SSH开启密钥登录 禁止Root用户登录
- 08-03从零开始的安卓Root教程
- 08-03Linux下 sudo命令
- 08-03Linux sudo命令9.3分高危漏洞被修复:可提权至root级别
- 08-03Linux忘记root密码了怎么办
- 08-03AWS EC2 Amazon Linux 2023 改root密码
- 08-03Linux系统中root用户无法创建文件夹
- 08-03linux用户管理命令passwd(仅root用户可用)
- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)