Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to back up Linux configuration files using Git

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use Git to back up Linux configuration files. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

When we use a Linux server, we sometimes need to back up our configuration files. The traditional backup method is to copy the file, rename it, and insert some characters at the end of the file.

However, if we use Git, we can easily manage backups of configuration files. In this article, I will demonstrate how to use Git to implement backups and manage backups. The environments I tested were CentOS 7 and RHEL 7.

First, install Git

[root@localhost ~] # yum install git

Check the Git version

[root@localhost] # git-- version git version 1.8.3.1 [root@localhost] #

Set initial parameters

Replace the user name and email in the following command with your own.

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

Initialize the Git database now

Because I am going to back up the network configuration file, I only need to initialize the Git database in the directory of the network configuration file.

[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] #

Type ls-an on the command line, and we can see that the ".git" folder is created.

Third, use the following command for backup

[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] #

When we execute the second command, it asks you to enter a comment like "Changes on 26 Oct 2015" and then save the file.

Use the following command to view the git log

[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]

Note: try to insert some useless characters in the ifcfg-enp0s3 file.

Restore the network configuration file from the Git database

[root@localhost network-scripts] # git reset-- hard 1269758e5f5b2fa3e0ad1fe507abaf73b646a33d HEAD is now at 1269758 Changes on 26 Oct 2015 [root@localhost network-scripts] #

Using the same git id as above, the id of git is different depending on your installation.

Verify that the files recovered from the git database are correct.

Thank you for reading! This is the end of this article on "how to use Git to back up Linux configuration files". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report