Scripting mount, log gathering, verifying and unmounting
I am trying to piece together some scripts that I've started and some that I've gotten from someone here and modified for my use. I've messed around a bit but 'm not very good at the if then when do. I am getting to do cronjobs for the scripts at intervals but if there is a way to piece this into one script. What I'm trying to do on a weekly basis is.
Any advice would be appreciated.
- Mount a partition to a windows share
- check to see if mounted if mounted do the log gathering
- Gather, tar and zip audit logs and data files and move to the mount point
- remove logs once they are backed up
- remove mapping
The scripts do run individualy so I know they work. The scripts I have are;
Check if mapped if not than map
----------------------------
#!/usr/bin/perl
print `date`;
$ismounted = `df -h |awk '{ print $1 }'|grep ShareName`;
chomp ($ismounted)
unless ($ismounted =~ /ShareName/) {
print "/mnt/dump is NOT mounted!\n";
print "Mounting /mnt/dump...\n";
/opt/temp/scripts/xxxx_dumpsharedcmd_conv.exp`;
} else {
print "/mnt/dump is already mounted.\n";
exit;
}
-----------------------------------------------------
This is the mapping script called in the script above
-----------------------------------------------------
#xxxx_dumpsharecmd_conv.exp
#!/usr/bin/expect
set timeout 20
#set password xxxxxxxxxxx
spawn mount -t cifs //xxx.xxx.xxx.xxx/ShareName/Hostname /mnt/dump -o username=xxxxxx,credentials=dump_cred,iocharset=utf8
,file_mode=0777,dir_mode=0777
#expect "Password:"
#send "$password\r"
expect eof
---------------------------------------------------------------------
This script gathers the logs and data and puts them (for now in a temp dir called /opt/backup but it will be /mnt/dump
--------------------------------------------------------------------
#Logs_Data_Backup
#!/bin/sh
# Logs and Data Backup Script
# This script backups up all of the data to the /opt/backup directory.
# The Administrator will still be required to move this file to
# external media to enable bare-metal restoration of the system.
#
yyyy=`date "+%Y"`
mm=`date "+%m"`
dd=`date "+%d"`
Month=`date "+%b"`
Day=`date "+%e"`
dstr=`date "+%Y%m%d"`
mkdir /opt/backup/Hostname_logs_${dstr}
mkdir /opt/backup/Hostname_data_${dstr}
#
# Log section
#
/bin/tar --create --verbose --preserve \
--ignore-failed-read --gzip -- file=/opt/backup/Hostname_logs_${dstr}/Hostname_logfiles_${dstr}.tgz \
`cat /opt/temp/scripts/backup_dirs-log.txt | xargs` \
>> /opt/backup/Hostname_logs_${dstr}/Hostname_log_filelist.txt
#
# Data section
#
/bin/tar --create --verbose --preserve \
--ignore-failed-read --gzip --file=/opt/backup/Hostname_data_${dstr}/Hostname_datafiles_${dstr}.tgz \
`cat /opt/temp/scripts/backup_dirs-data.txt | xargs` \
>> /opt/backup/Hostname_data_${dstr}/Hostname_data_filelist.txt
echo "Backup complete on " `date` \
>> /backup/filelist.txt
------------------------------------------------------------
This script deletes the logs (this will be the /var/log/audit and /var/log), it's /opt/temp/logs for testing.
This should clean the zipped files out so the next time this runs there will be another weeks worth of accumulated zipped log files to backup.
--------------------------------------------------------------
#delete_backedup_logs*
#!/bin/bash
find /opt/temp/logs/*.gz -exec rm {} \;
|