Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
systems:linux_maintenance_scripts [2011/07/29 16:17] 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 ==== | ||
+ | '' | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | ## script: ./ | ||
+ | |||
+ | #/ | ||
+ | #/ | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | ==== DHCP ==== | ||
+ | '' | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | ## script: ./ | ||
+ | |||
+ | #service isc-dhcp-server stop | ||
+ | #service isc-dhcp-server start | ||
+ | service isc-dhcp-server restart | ||
+ | |||
+ | # Check status | ||
+ | ps aux | grep dhcpd | ||
+ | </ | ||
+ | |||
+ | ==== Windows Server Mapping ==== | ||
+ | '' | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | ## script: ./ | ||
+ | ## Mount and map Windows backup server (for backup purposes) | ||
+ | mount -t cifs -o username=backuponly, | ||
+ | </ | ||
+ | |||
+ | ==== RSync ==== | ||
+ | '' | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | |||
+ | #rsync --verbose | ||
+ | # --recursive --times --perms --links --delete \ | ||
+ | # --exclude " | ||
+ | # 192.168.0.31: | ||
+ | |||
+ | # Website | ||
+ | rsync --archive --verbose --progress --stats --rsh=/ | ||
+ | --links --delete --exclude=stats 192.168.0.31:: | ||
+ | |||
+ | # Databases | ||
+ | rsync --archive --verbose --progress --stats --rsh=/ | ||
+ | --links --delete 192.168.0.31:: | ||
+ | |||
+ | # Root user home | ||
+ | rsync --archive --verbose --progress --stats --rsh=/ | ||
+ | --links --delete 192.168.0.31:: | ||
+ | |||
+ | # Subserver Repositories | ||
+ | rsync --archive --verbose --progress --stats --rsh=/ | ||
+ | --links --delete 192.168.0.31:: | ||
+ | </ | ||
+ | |||
+ | == Anti-spam / Anti-crack == | ||
+ | Run this script to scan the website and see signs of spamming or cracking: '' | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | ## script: scan-website.sh | ||
+ | ## | ||
+ | |||
+ | echo "Scan Website for vulnerabilities" | ||
+ | |||
+ | cd /var/www | ||
+ | find . -name " | ||
+ | find . -name " | ||
+ | find . -name " | ||
+ | find . -name " | ||
+ | find . -name " | ||
+ | find . -name " | ||
+ | less / | ||
+ | </ | ||
== Mail Spool Maintenance == | == Mail Spool Maintenance == | ||
Line 36: | Line 116: | ||
| '' | | '' | ||
== Backup Critical Data and Configuration == | == Backup Critical Data and Configuration == | ||
+ | |||
+ | ==== Backup Web Systems ==== | ||
Create a daily cron task to backup some important files to a directory (for example: ''/ | Create a daily cron task to backup some important files to a directory (for example: ''/ | ||
<code bash> | <code bash> | ||
Line 85: | Line 167: | ||
# mysqldump -u< | # mysqldump -u< | ||
# Restore with: | # Restore with: | ||
- | # mysql -u< | + | # mysql -u < |
mysqldump -uroot -pMyPass website_db > $TARGETDIR/ | mysqldump -uroot -pMyPass website_db > $TARGETDIR/ | ||
tar -czf $TARGETDIR/ | tar -czf $TARGETDIR/ | ||
Line 119: | Line 201: | ||
</ | </ | ||
+ | ==== Backup Subversion Repositories ==== | ||
Including Subversion repositories: | Including Subversion repositories: | ||
<code bash> | <code bash> | ||
Line 219: | Line 302: | ||
</ | </ | ||
+ | ==== Backup Databases ==== | ||
+ | Create a scrip '' | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | ## script: backup-db.sh | ||
+ | ## | ||
+ | |||
+ | # backup last 7 days | ||
+ | #export d=`date +%u` | ||
+ | # backup using date | ||
+ | export d=$(date +' | ||
+ | |||
+ | mkdir -p backup/$d | ||
+ | #for i in `echo "show tables" | ||
+ | for i in `echo "show tables" | ||
+ | do | ||
+ | echo $i; mysqldump --add-drop-table --allow-keywords -q -a -c -u username -ppassword database $i > backup/ | ||
+ | rm -f backup/ | ||
+ | gzip backup/ | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | ==== Backup to Window Server ==== | ||
+ | If you need to backup data to a remote Windows server (running Samba), use this script ''' | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | ## script: / | ||
+ | ## | ||
+ | |||
+ | ###!!!! THIS SCRIPT IS DISABLED | ||
+ | ###!!!! COMMENT OUT THIS NEXT LINE TO ENABLE | ||
+ | #exit 99 | ||
+ | |||
+ | # | ||
+ | # Define Target Directory | ||
+ | # | ||
+ | SOURCEDIR="/ | ||
+ | TARGETDIR="/ | ||
+ | |||
+ | # Verify if source is available, otherwise we bail out | ||
+ | if [ ! -d " | ||
+ | echo " Nothing to backup on $(date). Source directory $SOURCEDIR does not exist." | ||
+ | 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 " | ||
+ | mkdir $TARGETDIR | ||
+ | fi | ||
+ | |||
+ | # Perform operations if TargetDir exists | ||
+ | if [ -d " | ||
+ | # | ||
+ | # Mount Windows server samba drive (CIFS) | ||
+ | # | ||
+ | # Requires cifs-utils to be installed for mount to work. | ||
+ | mount -t cifs -o username=backuponly, | ||
+ | |||
+ | # | ||
+ | # Remove old backup files | ||
+ | # | ||
+ | rm -rf $TARGETDIR/ | ||
+ | |||
+ | # | ||
+ | # Backup | ||
+ | # | ||
+ | # Backup ALL files | ||
+ | #cp -R $SOURCEDIR $TARGETDIR | ||
+ | |||
+ | # Backup all files EXCEPT ' | ||
+ | # Method 1: cp *? | ||
+ | # Method 2: cp `ls $SOURCEDIR |grep -v < | ||
+ | cd $SOURCEDIR | ||
+ | cp `ls $SOURCEDIR | grep -v downloads` $TARGETDIR/ | ||
+ | |||
+ | # | ||
+ | # Send Reminder | ||
+ | # | ||
+ | ## send reminder to sysadmin to pull the tarball from the server. | ||
+ | echo " | ||
+ | echo " | ||
+ | echo " | ||
+ | echo " | ||
+ | #mail root@localhost -s "Get the backup tarball off the server" | ||
+ | |||
+ | else | ||
+ | |||
+ | ## send message to sysadmin. | ||
+ | echo " | ||
+ | echo " | ||
+ | #mail root@localhost -s " | ||
+ | |||
+ | fi | ||
+ | |||
+ | </ |