It is a best practice to backup a configuration file before performing any activity on a Linux system, which helps you to compare the configuration files in case of any issue occur.
You can automate this bash script by creating a cronjob, which can be scheduled based on your needs. However, we recommending to enable a cronjob once in a week nor month.
This script is very important for an environment where server restarts are not done frequently.
Also, as everything is a file in Linux, so it recommends running this script before fixing any VA/CR’s.
What does this script?
This script backs up the output of multiple commands and configuration files into a single file, and finally moves it to another server (aka jump server nor central server).
System details are as follows:
Server-A: Central Server / JUMP Server (local.2daygeek.com)
Server-B: Remote System-1 (CentOS7.2daygeek.com)
Server-C: Remote System-2 (CentOS8.2daygeek.com)
Bash Script to Backup Configuration files on Remote Linux Server
It consists of two scripts, one is the actual script and the other is a helper script, which helps execute the actual script from the JUMP/Central server, and it pulls the output file from the remote server once the script execution is complete.
Make a Note: Both scripts must be on the central server and you must have enabled passwordless authentication for client systems for seamless operation.
Actual Script:
Supporting nor helper script:
Finally run the sub-script that pushes the actual script to the given target servers. This script supports dynamic inventory, which means you just need to enter a list of IP nor Host_Name that you want to backup the configuration and hit ctrl+d.
Output:
You can see the output similar to the below one.
Final Thoughts
I hope this shell script very useful for backup your configuration files on remote Linux system.
If you have any questions or feedback, feel free to comment below.
The post How to Backup Configuration Files on Remote Linux System first appeared on 2DayGeek.