bckuprsync-script

Create a Shell Script to Backup Files and Directories Using rsync

This article we deliver shell scripts to backup your documents and directories from you nearby Linux system to a faraway Linux server the use of rsync command. This could be an interactive manner to carry out backup, in which you want to offer faraway backup server hostname/ip deal with and folder location. We maintain a separate report in which you want to offer documents and directories that want backup. We have brought scripts in which first script ask password after every report have been copied (when you have enabled ssh authentication keys , then password might be now no longer be asked) and in 2d script password might be precipitated most effective once. We are going to backup bckup.txt, dataconfig.txt, docs and oracledb.

[root@Fedora21 tmp]# ls -l
total 12
-rw-r–r–. 1 root root 0 May 15 10:43 bckrsync.sh
-rw-r–r–. 1 root root 0 May 15 10:44 bckup.txt
-rw-r–r–. 1 root root 0 May 15 10:46 dataconfig.txt
drwxr-xr-x. 2 root root 4096 May 15 10:45 docs
drwxr-xr-x. 2 root root 4096 May 15 10:44 oracledb

This file contains backup files / dir details

[root@Fedora21 tmp]# cat /tmp/bckup.txt
/tmp/oracledb
/tmp/dataconfig.txt
/tmp/docs
[root@Fedora21 tmp]#

Script 1 :

#!/bin/bash

#We will save path to backup file in variable
backupf='/tmp/bckup.txt'

#Next line just prints message
echo "Shell Script Backup Your Files / Directories Using rsync"

#next line check if entered value is not null, and if null it will reask user to enter Destination Server
while [ x$desthost = "x" ]; do

#next line prints what userd should enter, and stores entered value to variable with name desthost
read -p "Destination backup Server : " desthost

#next line finishes while loop
done

#next line check if entered value is not null, and if null it will reask user to enter Destination Path
while [ x$destpath = "x" ]; do

#next line prints what userd should enter, and stores entered value to variable with name destpath
read -p "Destination Folder : " destpath

#next line finishes while loop
done

#Next line will start reading backup file line by line
for line in `cat $backupf`

#and on each line will execute next
do

#print message that file/dir will be copied
echo "Copying $line ... "
#copy via rsync file/dir to destination

rsync -ar "$line" "$desthost":"$destpath"

#this line just print done
echo "DONE"

#end of reading backup file
done

Running the script with output

[root@Fedora21 tmp]# ./bckrsync.sh
Shell Script Backup Your Files / Directories Using rsync
Destination backup Server : 104.*.*.41
Destination Folder : /tmp
Copying /tmp/oracledb ...
The authenticity of host '104.*.*.41 (104.*.*.41)' can't be established.
ECDSA key fingerprint is 96:11:61:17:7f:fa:......
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '104.*.*.41' (ECDSA) to the list of known hosts.
root@104.*.*.41's password:
DONE
Copying /tmp/dataconfig.txt ...
root@104.*.*.41's password:
DONE
Copying /tmp/docs ...
root@104.*.*.41's password:
DONE
[root@Fedora21 tmp]#

Script 2 :

#!/bin/bash

#We will save path to backup file in variable
backupf='/tmp/bckup.txt'

#Next line just prints message
echo "Shell Script Backup Your Files / Directories Using rsync"

#next line check if entered value is not null, and if null it will reask user to enter Destination Server
while [ x$desthost = "x" ]; do

#next line prints what userd should enter, and stores entered value to variable with name desthost
read -p "Destination backup Server : " desthost

#next line finishes while loop
done

#next line check if entered value is not null, and if null it will reask user to enter Destination Path
while [ x$destpath = "x" ]; do

#next line prints what userd should enter, and stores entered value to variable with name destpath
read -p "Destination Folder : " destpath

#next line finishes while loop
done

#next line check if entered value is not null, and if null it will reask user to enter password
while [ x$password = "x" ]; do
#next line prints what userd should enter, and stores entered value to variable with name password. #To hide password we are using -s key
read -sp "Password : " password
#next line finishes while loop
done

#Next line will start reading backup file line by line
for line in `cat $backupf`

#and on each line will execute next
do

#print message that file/dir will be copied
echo "Copying $line ... "
#we will use expect tool to enter password inside script
/usr/bin/expect << EOD
#next line set timeout to -1, recommended to use
set timeout -1
#copy via rsync file/dir to destination, using part of expect — spawn command

spawn rsync -ar ${line} ${desthost}:${destpath}
#as result of previous command we expect “password” promtp
expect "*?assword:*"
#next command enters password from script
send "${password}\r"
#next command tells that we expect end of file (everything finished on remote server)
expect eof
#end of expect pard
EOD
#this line just print done
echo "DONE"

#end of reading backup file
done

Screenshot running the second script with output

Tags:

rsync, rsync linux, rsync ssh, rsync over ssh, rsync remote to local, linux rsync examples, bash script, shell script, bash in linux, linux script
nicholas-cappello-Wb63zqJ5gnE-unsplash

How to setup Munin monitoring system in CentOs

Hello Everybody! Welcome to our today’s article on one the maximum extensively used, freed from fee and Open Source Munin Network Resource Monitoring System. Its a perl software program utility assist you to tracking your every and each asset that continues document of it and sends you the important signals of offerings on your servers, switches, applications, and any every other gadgets linked on your community whether or not its your computers, community, garage or the entire IT infrastructure. It suggests all of the data in graphs via an internet interface that emphasis on plug and play capabilities. Munin has a grasp/node structure wherein the grasp connects to all of the nodes at ordinary durations and asks them for data, then stores the data in RRD documents to updates the graphs if needed. So, after finishing its set up a excessive wide variety of tracking plugins could be playing without a greater effort.

Prerequisites

Your structures hardware assets depends upon your very own necessities at the same time as in this newsletter we are able to be the use of the subsequent device aid for Munin set up on CentOS 7.

System Resources
Munin VersionMunin 2.0.25
Base OSCentOS Linux 7 (Core), 64-bit
RAM4 GB
CPU2.0 GHZ
Hard Disk30 G

Munin set up setup calls for the fundamental net server applications to be established at the server. So, after fundamental networking setup configure your hostname, IP deal with and firewall settings through preserving SELinux into permissive mode. Then begin putting in applications through replace your system first and permitting EPEL repository on it the usage of under commands.

# yum install epel-release
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
# yum update

You may be requested to press “Y” key and hit Enter to continue for putting in all required updates. Once the updates are efficiently hooked up to your machine then continue to the set up of Apache Web server.

Setup Apache Web Server

To setup your Apache net server, we want to begin with the aid of using putting in its bundle the use of the below ‘yum’ command.

# yum install httpd

Upon of of entirety of programs installation, begin and allow its carrier and test that its lively and enabled the usage of the subsequent instructions respectively.

# systemctl enable httpd
# systemctl start httpd
# systemctl status httpd

Installing Munin monitoring system

We can set up Munin and Munin Node the use of the below ‘yum’ command via its to be had repository on CentOS 7 as shown.

# yum install munin munin-node

Hit “Y” plus Enter key to begin set up of Munin and Munin Noe consisting of a big range its required dependencies. Once the set up is complete, begin its service and permit it at auto begin throughout reboot with the aid of using the use of the subsequent commands.

Configure Munin

Now configure Munin via way of means of open its default configuration the use of any editor as utilized in beneath command.

# vim /etc/munin/munin.conf

# a simple host tree, change localhost with your FQDN.

[localhost]
address 127.0.0.1
use_node_name yes
:wq!

After saving the Munin configuration document, Open its apache digital host configuration document to feature get admission to permissions on your network.

# vim /etc/httpd/conf.d/munin.conf

After saving the configuration record changes , restart apache internet server service the usage of command below.

# systemctl restart httpd

Now we’re going to upload a brand new person and password to the /etc/munin/munin-htpasswd record because the Munin facts are included with a username and password, so we want to setup the simple Apache Authentication.

# htpasswd -c /etc/munin/munin-htpasswd admin

This will upload a brand new person with the name “admin” and asks for the brand new password as shown.

# vi /etc/munin/munin-node.conf

host_name munin.clinerds.com

Save and near the report and restart munin-node offerings and get admission to the subsequent hyperlink via way of means of mentioning your FQDN or IP from the customer that is for your community that changed into allowed in configuration report. http://your_servers_IP/munin

Welcome to Munin Web Console

Here is the Munin dashboard, now you can check the graphs of your required servers.

We can customise Munin dashboard via way of means of including one of a kind to be had plugins and upload more than one node to it. While the use of its internet console we’ve got alternatives to create more than one companies and classes consistent with the desired organization of services. You can test and notice the popularity of your vital provider via way of means of establishing its graph from the Munin internet console with a purpose to display you the modern and beyond facts from its maintained hostory as proven in beneath image.

Conclusion

Munin installation has been setup. We desire you’ve got got loved studying this article. The set up of Munin is pretty simple, now in reality upload the purchaser node and begin tracking your entire IT infrastructure the usage of this superb device without paying any charges. Now revel in the usage of Munin in your surroundings and sense unfastened to proportion your mind or tips in comments section.

Tags:

munin, munin linux, munin ubuntu, munin github, munin cron, munin mysql, munin apache, munin centos 7, munin centos 8, centos munin, munin ping, munin node centos