Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
systems:linux_maintenance_scripts [2018/05/01 14:48]
smayr [Backup Critical Data and Configuration]
systems:linux_maintenance_scripts [2018/05/01 15:07] (current)
smayr [RSync]
Line 1: Line 1:
 == Linux Maintenance Scripts == == Linux Maintenance Scripts ==
  
 +== Services ==
 +==== BIND/DNS ====
 +''bind-restart.sh'':
 +<code bash>
 +#!/bin/bash
 +## script: ./bind-restart.sh
 +
 +#/etc/init.d/bind stop
 +#/etc/init.d/bind start
 +/etc/init.d/bind9 restart
 +</code>
 +
 +==== DHCP ====
 +''dhcpd-restart.sh'':
 +<code bash>
 +#!/bin/bash
 +## script: ./dhcpd-restart.sh
 +
 +#service isc-dhcp-server stop
 +#service isc-dhcp-server start
 +service isc-dhcp-server restart
 +
 +# Check status
 +ps aux | grep dhcpd
 +</code>
 +
 +==== Windows Server Mapping ====
 +''map-win-backup-server.sh'':
 +<code bash>
 +#!/bin/bash
 +## script: ./map-win-backup-server.sh
 +## Mount and map Windows backup server (for backup purposes)
 +mount -t cifs -o username=backuponly,password=backup //backupserver2/LinuxBackup /data/win-fileserver/
 +</code>
 +
 +==== RSync ====
 +''rsync-server.sh'':
 +<code bash>
 +#!/bin/bash
 +
 +#rsync --verbose  --progress --stats --compress --rsh=/usr/bin/ssh \
 +#      --recursive --times --perms --links --delete \
 +#      --exclude "*bak" --exclude "*~" \
 +#      192.168.0.31:webfiles /var/www/mirror
 +
 +# Website
 +rsync --archive --verbose --progress --stats --rsh=/usr/bin/ssh --recursive --times --perms 
 +  --links --delete --exclude=stats 192.168.0.31::webfiles /data/mirror/swdev/www
 +
 +# Databases
 +rsync --archive --verbose --progress --stats --rsh=/usr/bin/ssh --recursive --times --perms 
 +  --links --delete 192.168.0.31::databases /data/mirror/swdev/databases
 +
 +# Root user home
 +rsync --archive --verbose --progress --stats --rsh=/usr/bin/ssh --recursive --times --perms 
 +  --links --delete 192.168.0.31::root /data/mirror/swdev/root
 +
 +# Subserver Repositories
 +rsync --archive --verbose --progress --stats --rsh=/usr/bin/ssh --recursive --times --perms 
 +  --links --delete 192.168.0.31::repos /data/mirror/swdev/repos
 +</code>
 +
 +== Anti-spam / Anti-crack ==
 +Run this script to scan the website and see signs of spamming or cracking: ''scan-website.sh'':
 +<code bash>
 +#!/bin/bash
 +## script: scan-website.sh
 +##
 +
 +echo "Scan Website for vulnerabilities" > /tmp/scan.txt
 +
 +cd /var/www
 +find . -name "*.php.suspected" >> /tmp/scan.txt
 +find . -name "*.php" -exec grep -H "eval(" "{}" \; >> /tmp/scan.txt
 +find . -name "*.php" -exec grep -H "\$GLOBALS.*\\x" "{}" \; >> /tmp/scan.txt
 +find . -name "*.php" -exec grep -H "function.*for.*strlen.*isset" "{}" \; >> /tmp/scan.txt
 +find . -name "*.php" -exec grep -H '<iframe' "{}" \; >> /tmp/scan.txt
 +find . -name "*.php" -exec grep -H 'header(*Location:' "{}" \; >> /tmp/scan.txt
 +less /tmp/scan.txt
 +</code>
 == Mail Spool Maintenance == == Mail Spool Maintenance ==
  
Line 242: Line 322:
   gzip backup/$d/$i.sql   gzip backup/$d/$i.sql
 done done
 +</code>
 +
 +==== Backup to Window Server ====
 +If you need to backup data to a remote Windows server (running Samba), use this script '''backup-to-winserver.sh'':
 +<code bash>
 +#!/bin/bash
 +## script: /etc/cron.daily/backuptowinsvr
 +##
 +
 +###!!!! THIS SCRIPT IS DISABLED
 +###!!!! COMMENT OUT THIS NEXT LINE TO ENABLE
 +#exit 99
 +
 +#-----------------------------
 +# Define Target Directory
 +#-----------------------------
 +SOURCEDIR="/data/backup/$HOSTNAME"
 +TARGETDIR="/data/win-fileserver"
 +
 +# Verify if source is available, otherwise we bail out
 +if [ ! -d "$SOURCEDIR" ]; then
 +  echo " Nothing to backup on $(date). Source directory $SOURCEDIR does not exist." >> /var/log/backup.log
 +  echo " Nothing to backup on $(date)."
 +  echo " Source directory $SOURCEDIR does not exist."
 +  echo " Exiting."
 +  exit;
 +fi
 +
 +# Try to create and mount TargetDir if it does not exist
 +if [ ! -d "$TARGETDIR" ]; then
 +  mkdir $TARGETDIR
 +fi
 +
 +# Perform operations if TargetDir exists
 +if [ -d "$TARGETDIR" ]; then
 +  #------------------------------------------
 +  # Mount Windows server samba drive (CIFS)
 +  #------------------------------------------
 +  # Requires cifs-utils to be installed for mount to work.
 +  mount -t cifs -o username=backuponly,password=backup //backupserver2/LinuxBackup $TARGETDIR
 +
 +  #-----------------------------
 +  # Remove old backup files
 +  #-----------------------------
 +  rm -rf $TARGETDIR/$HOSTNAME/*
 +
 +  #-----------------------------
 +  # Backup
 +  #-----------------------------
 +  # Backup ALL files
 +  #cp -R $SOURCEDIR $TARGETDIR
 +
 +  # Backup all files EXCEPT 'downloads*' files
 +  # Method 1: cp *?[!excludepattern] $SOURCEDIR $TARGETDIR
 +  # Method 2: cp `ls $SOURCEDIR |grep -v <yourexcludepattern>` $TARGETDIR
 +  cd $SOURCEDIR
 +  cp `ls $SOURCEDIR | grep -v downloads` $TARGETDIR/$HOSTNAME
 +
 +  #-----------------------------
 +  # Send Reminder
 +  #-----------------------------
 +  ## send reminder to sysadmin to pull the tarball from the server.
 +  echo "Backup to Windows Backup Server Complete"
 +  echo "Nightly Backup to Windows Backup Server Completed: $(date)" >> /var/log/backup.log
 +  echo "Source: $SOURCEDIR" >> /var/log/backup.log
 +  echo "Target: $TARGETDIR" >> /var/log/backup.log
 +  #mail root@localhost -s "Get the backup tarball off the server"
 +
 +else
 +
 +  ## send message to sysadmin.
 +  echo "Backup to Windows Backup Server failed on $(date). %TARGETDIR does not exist" >> /var/log/backup.log
 +  echo "Backup to Windows Backup Server failed on $(date). %TARGETDIR does not exist"
 +  #mail root@localhost -s "Backup failed. %TARGETDIR does not exist"
 +
 +fi
 +
 </code> </code>