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 [2010/07/14 08:52] smayr |
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 48: | Line 130: | ||
# Try to create TargetDir if it does not exist | # Try to create TargetDir if it does not exist | ||
- | if cd $TARGETDIR; then | + | if ! cd $TARGETDIR; then |
- | cd / | + | |
- | else | + | |
mkdir $TARGETDIR | mkdir $TARGETDIR | ||
fi | fi | ||
Line 57: | Line 137: | ||
if cd $TARGETDIR; then | if cd $TARGETDIR; then | ||
- | | + | # |
# Remove old backup file | # Remove old backup file | ||
# | # | ||
- | rm -rf $TARGETDIR/ | + | |
# | # | ||
- | ## Backup | + | ## Backup |
# | # | ||
# Backup mail spool | # Backup mail spool | ||
- | tar -czvf $TARGETDIR/mailbackup.tar.gz / | + | |
+ | | ||
# Backup user directories | # Backup user directories | ||
- | tar -czvf $TARGETDIR/homesbackup.tar.gz /home | + | |
+ | | ||
+ | |||
+ | # Backup root user directories | ||
+ | rm -f $TARGETDIR/ | ||
+ | tar -czvf $TARGETDIR/ | ||
# Backup system settings, ie. /etc directory | # Backup system settings, ie. /etc directory | ||
+ | rm -f $TARGETDIR/ | ||
tar -czvf $TARGETDIR/ | tar -czvf $TARGETDIR/ | ||
# Backup MYSQL databases | # Backup MYSQL databases | ||
+ | rm -f $TARGETDIR/ | ||
tar -czvf $TARGETDIR/ | tar -czvf $TARGETDIR/ | ||
+ | # Hot backup with mysqldump command: | ||
+ | # mysqldump -u< | ||
+ | # Restore with: | ||
+ | # mysql -u < | ||
+ | mysqldump -uroot -pMyPass website_db > $TARGETDIR/ | ||
+ | tar -czf $TARGETDIR/ | ||
+ | |||
+ | # Backup SAMBA config files (when using tdbsam) | ||
+ | rm -f $TARGETDIR/ | ||
+ | tar -czvf $TARGETDIR/ | ||
# Backup website | # Backup website | ||
- | tar -czvf $TARGETDIR/ | + | |
+ | #tar -czvf $TARGETDIR/ | ||
+ | tar -czvf $TARGETDIR/ | ||
+ | rm -f $TARGETDIR/ | ||
+ | tar -czvf $TARGETDIR/ | ||
+ | # Backup database as SQL | ||
+ | |||
+ | # Backup projects | ||
+ | rm -f $TARGETDIR/ | ||
+ | tar -czvf $TARGETDIR/ | ||
# | # | ||
Line 94: | Line 201: | ||
</ | </ | ||
+ | ==== Backup Subversion Repositories ==== | ||
+ | Including Subversion repositories: | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | |||
+ | # | ||
+ | # Define Repository Directory | ||
+ | # | ||
+ | REPOSDIR="/ | ||
+ | TARGETDIR="/ | ||
+ | |||
+ | |||
+ | # | ||
+ | # Remove old Subversion dump file | ||
+ | # | ||
+ | rm -f $TARGETDIR/ | ||
+ | |||
+ | # | ||
+ | # Step 1: Backup your old Repository | ||
+ | # | ||
+ | # | ||
+ | # The first thing you need when moving from one server to another | ||
+ | # is a dump of your subversion repository. Hopefully you are already | ||
+ | # creating dump's with a backup script, but if not here's how you can | ||
+ | # create a subversion dump file: | ||
+ | # | ||
+ | # svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | svnadmin dump $REPOSDIR > $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | tar czf $TARGETDIR/ | ||
+ | |||
+ | rm -f $TARGETDIR/ | ||
+ | tar czf $TARGETDIR/ | ||
+ | |||
+ | # The dump file contains all the revisions you have ever made | ||
+ | # to your svn repository, so it will probably be quite large | ||
+ | # (it even includes files you may have deleted in a previous revision). | ||
+ | # | ||
+ | # | ||
+ | # Step 2: Create the new Repository | ||
+ | # | ||
+ | # | ||
+ | # Now, simply transfer the dump file on to your new subversion server, | ||
+ | # and create an empty repository: | ||
+ | # | ||
+ | # svnadmin create / | ||
+ | # svnadmin create $REPOSDIR | ||
+ | # | ||
+ | # | ||
+ | # Step 3: Import your old repository into the new one | ||
+ | # | ||
+ | # | ||
+ | # Next import your dump file: | ||
+ | # | ||
+ | # svnadmin load / | ||
+ | # svnadmin load $REPOSDIR < $TARGETDIR/ | ||
+ | |||
+ | ## send reminder to sysadmin to pull the tarball from the server. | ||
+ | #mail ttran -s "Get the backup tarball off the server" | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== 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 | ||
+ | |||
+ | </ |