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 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 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如何创建备份文件,如何备份Linux 配置文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA实现简单计算器布局与功能(附完整
- 下一篇: linux卸载xmind,Ubuntu下