Added rotate backups, updated diskalert for email
This commit is contained in:
parent
e0bb949686
commit
1909602caf
10
dbbackup.sh
10
dbbackup.sh
@ -5,6 +5,13 @@ DBUSER='dbbackup'
|
|||||||
DBPASS='EWFfP3GZsqr427Yj'
|
DBPASS='EWFfP3GZsqr427Yj'
|
||||||
BACKUPDIR='/BACKUP/db/'
|
BACKUPDIR='/BACKUP/db/'
|
||||||
|
|
||||||
|
rotate_backups() {
|
||||||
|
find /BACKUP/db/ -type f -mtime +7 -exec rm -fr {} \;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rotate_backups
|
||||||
|
|
||||||
databases=`mysql --user=$DBUSER --password=$DBPASS -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
|
databases=`mysql --user=$DBUSER --password=$DBPASS -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
|
||||||
|
|
||||||
for db in $databases; do
|
for db in $databases; do
|
||||||
@ -13,5 +20,6 @@ for db in $databases; do
|
|||||||
mysqldump --force --opt --user=$DBUSER --password=$DBPASS --databases $db > $BACKUPDIR/$db.`date +%Y%m%d`.sql
|
mysqldump --force --opt --user=$DBUSER --password=$DBPASS --databases $db > $BACKUPDIR/$db.`date +%Y%m%d`.sql
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
81
diskalert.sh
81
diskalert.sh
@ -1,14 +1,73 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
source /etc/profile
|
MAILTO="mmckinnon@comprofix.com"
|
||||||
|
SMTP=mail.comprofix.com
|
||||||
|
LOGFILE="/var/log/diskalert.log"
|
||||||
|
THISSERVER=`hostname --fqdn`
|
||||||
|
MAILFROM="mmckinnon@comprofix.com"
|
||||||
|
|
||||||
|
startlogging() {
|
||||||
|
echo $DASHES2 >> $LOGFILE
|
||||||
|
echo "$0 started running at `date`" >> $LOGFILE
|
||||||
|
echo $DASHES2 >> $LOGFILE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
stoplogging() {
|
||||||
|
echo "`date` [MESSAGE] $0 finished runnning" >> $LOGFILE
|
||||||
|
echo $DASHES >> $LOGFILE
|
||||||
|
}
|
||||||
|
|
||||||
|
DASHES="---------------------------------------------------------------------------------"
|
||||||
|
DASHES2="================================================================================="
|
||||||
|
|
||||||
|
declare -a DEVICES
|
||||||
|
index=0
|
||||||
|
|
||||||
|
startlogging
|
||||||
|
|
||||||
|
for i in $( df -h | grep "/dev/" | grep -v tmpfs | awk '{print $1}' );
|
||||||
|
do
|
||||||
|
DEVICES[$index]=$i
|
||||||
|
let "index += 1"
|
||||||
|
done
|
||||||
|
|
||||||
|
for i in ${DEVICES[@]};
|
||||||
|
do
|
||||||
|
let space=`df -Pk $i | grep -v ^File | awk '{printf ("%i", $5) }'`
|
||||||
|
if [ $space -le 89 ]
|
||||||
|
then
|
||||||
|
echo "`date` [MESSAGE] Disk space usage on $i acceptable. $space% currently in use." >> $LOGFILE
|
||||||
|
fi
|
||||||
|
if [ $space -ge 90 ]
|
||||||
|
then
|
||||||
|
|
||||||
|
echo "`date` [WARNING] $i is running out of disk space. $space% currently in use." >> $LOGFILE
|
||||||
|
echo "
|
||||||
|
Hello,
|
||||||
|
|
||||||
|
You are running out of disk space on $THISSERVER.
|
||||||
|
|
||||||
|
Your $i is currently using $space% of disk space.
|
||||||
|
|
||||||
|
See the logfile for more info: vim $LOGFILE
|
||||||
|
|
||||||
|
Regards, " >/tmp/diskalertmail.msg
|
||||||
|
|
||||||
|
cat /tmp/diskalertmail.msg | sendemail -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILTO>" -u "[$THISSERVER] is running out of disk space"
|
||||||
|
echo "`date` [MESSAGE] Running out of disk space email sent to $MAILTO" >> $LOGFILE
|
||||||
|
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
stoplogging
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
devnames=`df -h | grep "/dev/" | awk '{print $1}'`
|
|
||||||
for devname in $devnames
|
|
||||||
do
|
|
||||||
let p=`df -Pk $devname | grep -v ^File | awk '{printf ("%i", $5) }'`
|
|
||||||
if [ $p -ge 90 ]
|
|
||||||
then
|
|
||||||
df -h $devname > /dev/null
|
|
||||||
echo "Running out of space \"$devname ($p%)\" on $(hostname) as on $(date)"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
mkdir -p /BACKUP/gitlab
|
# Add the following lines to /etc/gitlab/gitlab.rb once added
|
||||||
chown -R git:git /BACKUP/gitlab
|
# run gitlab-ctl reconfigure for changes to take effect
|
||||||
|
#
|
||||||
|
# gitlab_rails['backup_path'] = '<BACKUP FOLDER>'
|
||||||
|
# gitlab_rails['backup_keep_time'] = 604800 #7 days of backups to keep
|
||||||
|
|
||||||
gitlab-rake gitlab:backup:create
|
gitlab-rake gitlab:backup:create
|
||||||
|
22
svnbackup.sh
22
svnbackup.sh
@ -1,26 +1,22 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
bakdate=$(date +%Y%m%d%H%M)
|
bakdate=$(date +%Y%m%d%H%M)
|
||||||
echo "--------------------------------"
|
|
||||||
echo "Running SVN backup $bakdate"
|
|
||||||
echo "--------------------------------\n"
|
|
||||||
|
|
||||||
svnrepos="/var/lib/svn"
|
|
||||||
echo "\nGoing to backup all SVN repos located at: $svnrepos \n"
|
|
||||||
|
|
||||||
bakdest="/BACKUP/svn/"
|
bakdest="/BACKUP/svn/"
|
||||||
|
svnrepos="/var/lib/svn"
|
||||||
|
|
||||||
|
rotate_backups() {
|
||||||
|
find /BACKUP/svn/ type f -mtime +7 -exec rm -fr {} \;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rotate_backups
|
||||||
|
|
||||||
|
|
||||||
cd $svnrepos
|
cd $svnrepos
|
||||||
|
|
||||||
if [ -d "$bakdest" ] && [ -w "$bakdest" ] ; then
|
if [ -d "$bakdest" ] && [ -w "$bakdest" ] ; then
|
||||||
for repo in *; do
|
for repo in *; do
|
||||||
echo "Taking backup/svndump for: $repo"
|
|
||||||
echo "Executing : svnadmin dump $repo > $bakdest/$repo-$bakdate.svn.dump \n"
|
|
||||||
svnadmin dump $repo > $bakdest/$repo-$bakdate.svn.dump
|
svnadmin dump $repo > $bakdest/$repo-$bakdate.svn.dump
|
||||||
done
|
done
|
||||||
else
|
|
||||||
echo "Unable to continue SVN backup process."
|
|
||||||
echo "$bakdest is *NOT* a directory or you do not have write permission."
|
|
||||||
fi
|
fi
|
||||||
echo "\n\n================================="
|
|
||||||
echo " - Backup Complete, THANK YOU :-]"
|
|
||||||
|
@ -4,6 +4,14 @@ DATE=$(date +%Y%m%d%H%M)
|
|||||||
BACKUPDIR='/BACKUP/www'
|
BACKUPDIR='/BACKUP/www'
|
||||||
WWW='/var/www/'
|
WWW='/var/www/'
|
||||||
|
|
||||||
|
rotate_backups() {
|
||||||
|
find /BACKUP/www/ -type f -mtime +7 -exec rm -fr {} \;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rotate_backups
|
||||||
|
|
||||||
|
|
||||||
cd $WWW
|
cd $WWW
|
||||||
|
|
||||||
for folder in `ls -d *`; do
|
for folder in `ls -d *`; do
|
||||||
|
Loading…
Reference in New Issue
Block a user