I want to check the size, as well as if the backup completed successfully before replacing the old files on the remote server with the newly created files.
This is what my scripts looks like:
Code:
#!/bin/bash
# ===================================================================== #
# OTRS BACKUP SCRIPT WITH SYSTEM INFORMATION #
# SCRIPT CREATED 15/11/2012 #
# SCRIPT LAST MODIFIED 10/01/2013 #
# ===================================================================== #
# ===================================================================== #
# VARIABLES THAT CAN BE USED IN THE SCRIPT #
# ===================================================================== #
# DIRECTORY WHERE FILES ARE STORED
BACKUPDIR="/app/temp"
# CREATES A TITLE VARIABLE
TITLE="OTRS System Status"
# SPECIFY THE CONTENT OF THE E-MAIL TO BE SENT
MAILCONTENT="files"
# SETS THE MAXIMUM SIZE OF THE E-MAIL 4000 = +/- 5MB
MAXATTSIZE="4000"
# E-MAIL ADDRESS WHERE THE E-MAIL WILL BE SENT
# MAILADDR="myemail@mydomain.commyemail2@mydomain.com"
MAILADDR="myemail@mydomain.commyemail3@mydomain.com"
# DEFINE THE E-MAIL BODY
SUBJECTFILE=$BACKUPDIR/sqldump.txt
# CREATE THE FILE TO ATTACH
ATTACHMENT=status.html
# ===================================================================== #
# FUNCTIONS #
# STUBBING IS USED AS A TEMPORY PLACE HOLDER FOR FUTURE CODE #
# ===================================================================== #
MYSQL_DUMP ()
{
mysqldump systembackup > systembackup.sql --user=root --password=mypassword && mysqldump systembackup2 > systembackup2.sql --user=root --password=mypassword
}
# ---- END OF MYSQL DUMP ---- #
COMPRESSION ()
{
tar -jcvf systembackup.tar.bz2 systembackup.sql && tar -jcvf systembackup2.tar.bz2 systembackup2.sql
}
# ---- END OF COMPRESSION ---- #
REMOVE_FILES ()
{
rm systembackup.sql && rm systembackup2.sql && rm systembackup.tar.bz2 && rm systembackup2.tar.bz2
}
# ---- END OF COMPRESSION ---- #
DRIVE_SPACE ()
{
echo "<h2>Filesystem Storage</h2>"
echo "<pre>"
df -h
echo "</pre>"
}
# ---- END OF DRIVE SPACE ---- #
BACKUP_SIZE ()
{
echo "<h2>Backup Size</h2>"
echo "<pre>"
du -h systembackup.tar.bz2 && du systembackup.tar.bz2
du -h systembackup2.tar.bz2 && du systembackup2.tar.bz2
echo "</pre>"
}
# ---- END OF BACKUP SIZE ---- #
FILE_COMPARE ()
{
echo "<pre>"
if [ systembackup.sql -nt systembackup.sql ] && [ systembackup2.sql -nt systembackup2.sql ]; then
echo "New file created"
else
echo "No change identified"
fi
echo "</pre>"
}
# ---- END OF FILE COMPARE ---- #
MOVE_OFF_SERVER ()
{
scp systembackup.tar.bz2 root@255.255.255.10:/systembackupbackup
echo $?
scp systembackup2.tar.bz2 root@255.255.255.10:/systembackupbackup
}
# ---- END OF FILE MOVE ---- #
# ===================================================================== #
# GATHERS AND DISPLAYS THE STATUS OF THE SYSTEM #
# ===================================================================== #
ATTACHMENT ()
{
cat <<- _status_ > $ATTACHMENT
<html>
<head>
<title>$TITLE</title>
</head>
<body>
<h1>$TITLE</h1>
<p></p>
$(DRIVE_SPACE)
$(BACKUP_SIZE)
$(FILE_COMPARE)
<body>
</html>
_status_
}
# ---- CALL THE FUNCTION TO CREATE AND ATTACH THE FILE ---- #
# ===================================================================== #
# EXECUTING FUNCTIONS #
# ===================================================================== #
# ---- CALL INDIVIDUAL FUNCTIONS IN CORRECT SEQUENCE ---- #
cd $BACKUPDIR
MYSQL_DUMP
COMPRESSION
MOVE_OFF_SERVER
ATTACHMENT
REMOVE_FILES
# ===================================================================== #
# GATHERS INFORMATION AND SEND MESSAGE ATTACHMENT #
# ===================================================================== #
if [ "$MAILCONTENT" = "files" ]
then
uuencode $ATTACHMENT $ATTACHMENT | mailx -s "System Status $DATE" -- $MAILADDR
fi
exit 0
Last edited by SalientAnimal; 01-14-2013 at 02:42 AM..
Reason: Adding Code
I probably could have done this at one time, but, the years and no need has left my scripting skills lacking and I'm unable to work this problem out. https://www.unix.com/images/smilies/frown.gif
:(
Using Linux, have a great many xml files in which there may be multiple occurrence of a line of... (13 Replies)
Hi All,
How do I search first string & second string and copy all content between them from one file to another file?
Please help me..
Thanks In Advance.
Regards,
Pankaj (12 Replies)
Hiiii Friends
I have 2 files with huge data. I want to compare this 2 files & if they hav same set of vales in specific rows & columns i need to get that value from one file & replace it in other.
For example: I have few set data of both files here:
a.dat:
PDE-W 2009 12 16 5 29 11.11 ... (10 Replies)
Hello All
I have a xml file with many sets of records
like this
<mytag>mydata</mytag>
<tag2>data&</tag2>
also same file can be like this
<mytag>mydata</mytag>
<tag2>data&</tag2>
<tag3>data2&data3</tag3>
Now i can grep & and replace with & for whole file but it will replace all... (4 Replies)
how can i copy a certain word from a text file then use this word to replace in another text file??
i tried to use something like:
awk '{print "Hit the",$1,"with your",$2}' /aaa/qqqq.txt > uu.txt
but i can't add an argument to point to the second file which i will replace in.
please... (8 Replies)
Beginner/Intermediate shell; comfortable in the command line.
I have been looking for a solution to a backup problem. I need to compare Directory 1 to Directory 2 and copy all modified or new files/directories from Directory 1 to Directory 3. I need the directory and file structure to be... (4 Replies)
All,
I have to copy huge file from one location to another using python . I want to make sure the execution of Copy command is successful and all the files are copied properly (there has not been any abrupt interruption to the copy process or error like no space available is encountered during... (5 Replies)
// Redhat
I have this code working, but need to add one more qualification so that I don't overwrite the files.
#!/bin/sh
cd /P2/log/cerner_prod/millennium/archive/
for f in *
do || continue #If this isn't a regular file, skip it.
&& continue #If a backup already... (2 Replies)
Sometimes when I boot, my system goes into emergency mode.
I then use Clonezilla to restore an image.
Usually the image is older than the current date.
This is part of a backup script that runs as a startup program.
cd /home/andy/bin/
zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py... (22 Replies)