Server Administration
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesServer Administration

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 20th, 2005, 10:22 PM
portal's Avatar
portal portal is offline
PHP Newb
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: East Coast
Posts: 155 portal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 17 sec
Reputation Power: 3
Send a message via AIM to portal Send a message via MSN to portal
Cron job: need to replace mutt command, need assistance

I hope this is the right place to be posting this. I'm trying to run a cron job, but mutt isn't installed. My webhost says sendmail is what to use.

The line in the script is:

if [ $MAXATTSIZE -ge $ATTSIZE ]
then
BACKUPFILES=`echo "$BACKUPFILES" | sed -e "s# # -a #g"` #enable multiple attachments
mutt -s "MySQL Backup Log and SQL Files for $HOST - $DATE" $BACKUPFILES $MAILADDR < $LOGFILE
else
cat "$LOGFILE" | mail -s "WARNING! - MySQL Backup exceeds set maximum attachment size on $HOST - $DATE" $MAILADDR


I've tried rewriting the mutt part but I only get errors.

Reply With Quote
  #2  
Old August 22nd, 2005, 08:44 AM
Milo Milo is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Italy
Posts: 192 Milo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Cron job: need to replace mutt command, need assistance

What exactly are you writing in the sendmail function???

Reply With Quote
  #3  
Old August 23rd, 2005, 01:05 PM
portal's Avatar
portal portal is offline
PHP Newb
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: East Coast
Posts: 155 portal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 17 sec
Reputation Power: 3
Send a message via AIM to portal Send a message via MSN to portal
RE: Cron job: need to replace mutt command, need assistance

Not really php but figured I'd put it in tags just to be safe. Here's the whole code.

php Code:
Original - php Code
  1. #!/bin/bash
  2. #
  3. # MySQL Backup Script
  4. # VER. 2.2 - http://sourceforge.net/projects/automysqlbackup/
  5. # Copyright (c) 2002-2003 wipe_out@lycos.co.uk
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20. #
  21. #=================================================  ====================
  22. #=================================================  ====================
  23. # Set the following variables to your system needs
  24. # (Detailed instructions below variables)
  25. #=================================================  ====================
  26.  
  27. # Username to access the MySQL server e.g. dbuser
  28. USERNAME=exampleusername
  29.  
  30. # Username to access the MySQL server e.g. password
  31. PASSWORD=examplepw
  32.  
  33. # Host name (or IP address) of MySQL server e.g localhost
  34. DBHOST=localhost
  35.  
  36. # List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
  37. DBNAMES="all"
  38.  
  39. # Backup directory location e.g /backups
  40. BACKUPDIR="/home/mysite/public_html/backupdb"
  41.  
  42. # Mail setup
  43. # What would you like to be mailed to you?
  44. # - log   : send only log file
  45. # - files : send log file and sql files as attachments (see docs)
  46. # - stdout : will simply output the log to the screen if run manually.
  47. MAILCONTENT="files"
  48.  
  49. # Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs])
  50. MAXATTSIZE="8000"
  51.  
  52. # Email Address to send mail to? (user@domain.com)
  53. MAILADDR="email@mysite.com"
  54.  
  55.  
  56. # ==================================================  ==========
  57. # === ADVANCED OPTIONS ( Read the doc's below for details )===
  58. #=================================================  ============
  59.  
  60. # List of DBBNAMES for Monthly Backups.
  61. MDBNAMES="mysql $DBNAMES"
  62.  
  63. # List of DBNAMES to EXCLUDE if DBNAMES are set to all (must be in " quotes)
  64. DBEXCLUDE=""
  65.  
  66. # Include CREATE DATABASE in backup?
  67. CREATE_DATABASE=no
  68.  
  69. # Separate backup directory and file for each DB? (yes or no)
  70. SEPDIR=yes
  71.  
  72. # Which day do you want weekly backups? (1 to 7 where 1 is Monday)
  73. DOWEEKLY=4
  74.  
  75. # Choose Compression type. (gzip or bzip2)
  76. COMP=gzip
  77.  
  78. # Command to run before backups (uncomment to use)
  79. #PREBACKUP="/etc/mysql-backup-pre"
  80.  
  81. # Command run after backups (uncomment to use)
  82. #POSTBACKUP="/etc/mysql-backup-post"
  83.  
  84. #=================================================  ====================
  85. # Options documantation
  86. #=================================================  ====================
  87. # Set USERNAME and PASSWORD of a user that has at least SELECT permission
  88. # to ALL databases.
  89. #
  90. # Set the DBHOST option to the server you wish to backup, leave the
  91. # default to backup "this server".(to backup multiple servers make
  92. # copies of this file and set the options for that server)
  93. #
  94. # Put in the list of DBNAMES(Databases)to be backed up. If you would like
  95. # to backup ALL DBs on the server set DBNAMES="all".(if set to "all" then
  96. # any new DBs will automatically be backed up without needing to modify
  97. # this backup script when a new DB is created).
  98. #
  99. # If the DB you want to backup has a space in the name replace the space
  100. # with a % e.g. "data base" will become "data%base"
  101. # NOTE: Spaces in DB names may not work correctly when SEPDIR=no.
  102. #
  103. # You can change the backup storage location from /backups to anything
  104. # you like by using the BACKUPDIR setting..
  105. #
  106. # The MAILCONTENT and MAILADDR options and pretty self explanitory, use
  107. # these to have the backup log mailed to you at any email address or multiple
  108. # email addresses in a space seperated list.
  109. # (If you set mail content to "log" you will require access to the "mail" program
  110. # on your server. If you set this to "files" you will have to have mutt installed
  111. # on your server. If you set it sto stdout it will log to the screen if run from
  112. # the console or to the cron job owner if run through cron)
  113. #
  114. # MAXATTSIZE sets the largest allowed email attachments total (all backup files) you
  115. # want the script to send. This is the size before it is encoded to be sent as an email
  116. # so if your mail server will allow a maximum mail size of 5MB I would suggest setting
  117. # MAXATTSIZE to be 25% smaller than that so a setting of 4000 would probably be fine.
  118. #
  119. # Finally copy automysqlbackup.sh to anywhere on your server and make sure
  120. # to set executable permission. You can also copy the script to
  121. # /etc/cron.daily to have it execute automatically every night or simply
  122. # place a symlink in /etc/cron.daily to the file if you wish to keep it
  123. # somwhere else.
  124. # NOTE:On Debian copy the file with no extention for it to be run
  125. # by cron e.g just name the file "automysqlbackup"
  126. #
  127. # Thats it..
  128. #
  129. #
  130. # === Advanced options doc's ===
  131. #
  132. # The list of MDBNAMES is the DB's to be backed up only monthly. You should
  133. # always include "mysql" in this list to backup your user/password
  134. # information along with any other DBs that you only feel need to
  135. # be backed up monthly. (if using a hosted server then you should
  136. # probably remove "mysql" as your provider will be backing this up)
  137. # NOTE: If DBNAMES="all" then MDBNAMES has no effect as all DBs will be backed
  138. # up anyway.
  139. #
  140. # If you set DBNAMES="all" you can configure the option DBEXCLUDE. Other
  141. # wise this option will not be used.
  142. # This option can be used if you want to backup all dbs, but you want
  143. # exclude some of them. (eg. a db is to big).
  144. #
  145. # Set CREATE_DATABASE to "yes" (the default) if you want your SQL-Dump to create
  146. # a database with the same name as the original database when restoring.
  147. # Saying "no" here will allow your to specify the database name you want to
  148. # restore your dump into, making a copy of the database by using the dump
  149. # created with automysqlbackup.
  150. # NOTE: Not used if SEPDIR=no
  151. #
  152. # The SEPDIR option allows you to choose to have all DBs backed up to
  153. # a single file (fast restore of entire server in case of crash) or to
  154. # seperate directories for each DB (each DB can be restored seperately
  155. # in case of single DB corruption or loss).
  156. #
  157. # To set the day of the week that you would like the weekly backup to happen
  158. # set the DOWEEKLY setting, this can be a value from 1 to 7 where 1 is Monday,
  159. # The default is 6 which means that weekly backups are done on a Saturday.
  160. #
  161. # COMP is used to choose the copmression used, options are gzip or bzip2.
  162. # bzip2 will produce slightly smaller files but is more processor intensive so
  163. # may take longer to complete.
  164. #
  165. # Use PREBACKUP and POSTBACKUP to specify Per and Post backup commands
  166. # or scripts to perform tasks either before or after the backup process.
  167. #
  168. #
  169. #=================================================  ====================
  170. # Backup Rotation..
  171. #=================================================  ====================
  172. #
  173. # Daily Backups are rotated weekly..
  174. # Weekly Backups are run by default on Saturday Morning when
  175. # cron.daily scripts are run...Can be changed with DOWEEKLY setting..
  176. # Weekly Backups are rotated on a 5 week cycle..
  177. # Monthly Backups are run on the 1st of the month..
  178. # Monthly Backups are NOT rotated automatically...
  179. # It may be a good idea to copy Monthly backups offline or to another
  180. # server..
  181. #
  182. #=================================================  ====================
  183. # Please Note!!
  184. #=================================================  ====================
  185. #
  186. # I take no resposibility for any data loss or corruption when using
  187. # this script..
  188. # This script will not help in the event of a hard drive crash. If a
  189. # copy of the backup has not be stored offline or on another PC..
  190. # You should copy your backups offline regularly for best protection.
  191. #
  192. # Happy backing up...
  193. #
  194. #=================================================  ====================
  195. # Restoring
  196. #=================================================  ====================
  197. # Firstly you will need to uncompress the backup file.
  198. # eg.
  199. # gunzip file.gz (or bunzip2 file.bz2)
  200. #
  201. # Next you will need to use the mysql client to restore the DB from the
  202. # sql file.
  203. # eg.
  204. # mysql --user=username --pass=password --host=dbserver database < /path/file.sql
  205. # or
  206. # mysql --user=username --pass=password --host=dbserver -e "source /path/file.sql" database
  207. #
  208. # NOTE: Make sure you use "<" and not ">" in the above command because
  209. # you are piping the file.sql to mysql and not the other way around.
  210. #
  211. # Lets hope you never have to use this.. :)
  212. #
  213. #=================================================  ====================
  214. # Change Log
  215. #=================================================  ====================
  216. #
  217. # VER 2.2 - (2004-12-05)
  218. #    Changed from using depricated "-N" to "--skip-column-names".
  219. #    Added ability to have compressed backup's emailed out. (code from Thomas Heiserowski)
  220. #    Added maximum attachment size setting.
  221. # VER 2.1 - (2004-11-04)
  222. #    Fixed a bug in daily rotation when not using gzip compression. (Fix by Rob Rosenfeld)
  223. # VER 2.0 - (2004-07-28)
  224. #    Switched to using IO redirection instead of pipeing the output to the logfile.
  225. #    Added choice of compression of backups being gzip of bzip2.
  226. #    Switched to using functions to facilitate more functionality.
  227. #    Added option of either gzip or bzip2 compression.
  228. # VER 1.10 - (2004-07-17)
  229. #    Another fix for spaces in the paths (fix by Thomas von Eyben)
  230. #    Fixed bug when using PREBACKUP and POSTBACKUP commands containing many arguments.
  231. # VER 1.9 - (2004-05-25)
  232. #    Small bug fix to handle spaces in LOGFILE path which contains spaces (reported by Thomas von Eyben)
  233. #    Updated docs to mention that Log email can be sent to multiple email addresses.
  234. # VER 1.8 - (2004-05-01)
  235. #    Added option to make backups restorable to alternate database names
  236. #    meaning that a copy of the database can be created (Based on patch by Rene Hoffmann)
  237. #    Seperated options into standard and advanced.
  238. #    Removed " from single file dump DBMANES because it caused an error but
  239. #    this means that if DB's have spaces in the name they will not dump when SEPDIR=no.
  240. #    Added -p option to mkdir commands to create multiple subdirs without error.
  241. #    Added disk usage and location to the bottom of the backup report.
  242. # VER 1.7 - (2004-04-22)
  243. #    Fixed an issue where weelky backups would only work correctly if server
  244. #    locale was set to English (issue reported by Tom Ingberg)
  245. #    used "eval" for "rm" commands to try and resolve rotation issues.
  246. #    Changed name of status log so multiple scripts can be run at the same time.
  247. # VER 1.6 - (2004-03-14)
  248. #   Added PREBACKUP and POSTBACKUP command functions. (patch by markpustjens)
  249. #   Added support for backing up DB's with Spaces in the name.
  250. #   (patch by markpustjens)
  251. # VER 1.5 - (2004-02-24)
  252. #   Added the ability to exclude DB's when the "all" option is used.
  253. #   (Patch by kampftitan)
  254. # VER 1.4 - (2004-02-02)
  255. #   Project moved to Sourceforge.net
  256. # VER 1.3 - (2003-09-25)
  257. #   Added support for backing up "all" databases on the server without
  258. #    having to list each one seperately in the configuration.
  259. #   Added DB restore instructions.
  260. # VER 1.2 - (2003-03-16)
  261. #   Added server name to the backup log so logs from multiple servers
  262. #   can be easily identified.
  263. # VER 1.1 - (2003-03-13)
  264. #   Small Bug fix in monthly report. (Thanks Stoyanski)
  265. #   Added option to email log to any email address. (Inspired by Stoyanski)
  266. #   Changed Standard file name to .sh extention.
  267. #   Option are set using yes and no rather than 1 or 0.
  268. # VER 1.0 - (2003-01-30)
  269. #   Added the ability to have all databases backup to a single dump
  270. #   file or seperate directory and file for each database.
  271. #   Output is better for log keeping.
  272. # VER 0.6 - (2003-01-22)
  273. #   Bug fix for daily directory (Added in VER 0.5) rotation.
  274. # VER 0.5 - (2003-01-20)
  275. #   Added "daily" directory for daily backups for neatness (suggestion by Jason)
  276. #   Added DBHOST option to allow backing up a remote server (Suggestion by Jason)
  277. #   Added "--quote-names" option to mysqldump command.
  278. #   Bug fix for handling the last and first of the year week rotation.
  279. # VER 0.4 - (2002-11-06)
  280. #   Added the abaility for the script to create its own directory structure.
  281. # VER 0.3 - (2002-10-01)
  282. #   Changed Naming of Weekly backups so they will show in order.
  283. # VER 0.2 - (2002-09-27)
  284. #   Corrected weekly rotation logic to handle weeks 0 - 10
  285. # VER 0.1 - (2002-09-21)
  286. #   Initial Release
  287. #
  288. #=================================================  ====================
  289. #=================================================  ====================
  290. #=================================================  ====================
  291. #
  292. # Should not need to be modified from here down!!
  293. #
  294. #=================================================  ====================
  295. #=================================================  ====================
  296. #=================================================  ====================
  297. PATH=/usr/local/bin:/usr/bin:/bin
  298. DATE=`date +%Y-%m-%d`            # Datestamp e.g 2002-09-21
  299. DOW=`date +%A`          # Day of the week e.g. Monday
  300. DNOW=`date +%u`     # Day number of the week 1 to 7 where 1 represents Monday
  301. DOM=`date +%d`          # Date of the Month e.g. 27
  302. M=`date +%B`                    # Month e.g January
  303. W=`date +%V`                    # Week Number e.g 37
  304. VER=2.2      # Version Number
  305. LOGFILE=$BACKUPDIR/$DBHOST-`date +%N`.log   # Logfile Name
  306. OPT="--quote-names --opt"         # OPT string for use with mysqldump ( see man mysqldump )
  307. BACKUPFILES=""          # thh: added for later mailing
  308.  
  309. # Create required directories
  310. if [ ! -e "$BACKUPDIR" ]        # Check Backup Directory exists.
  311.     then
  312.     mkdir -p "$BACKUPDIR"
  313. fi
  314.  
  315. if [ ! -e "$BACKUPDIR/daily" ]    # Check Daily Directory exists.
  316.     then
  317.     mkdir -p "$BACKUPDIR/daily"
  318. fi
  319.  
  320. if [ ! -e "$BACKUPDIR/weekly" ]  # Check Weekly Directory exists.
  321.     then
  322.     mkdir -p "$BACKUPDIR/weekly"
  323. fi
  324.  
  325. if [ ! -e "$BACKUPDIR/monthly" ]    # Check Monthly Directory exists.
  326.     then
  327.     mkdir -p "$BACKUPDIR/monthly"
  328. fi
  329.  
  330.  
  331. # IO redirection for logging.
  332. touch $LOGFILE
  333. exec 6>&1           # Link file descriptor #6 with stdout.
  334.                     # Saves stdout.
  335. exec > $LOGFILE     # stdout replaced with file $LOGFILE.
  336.  
  337.  
  338. # Functions
  339.  
  340. # Database dump function
  341. dbdump () {
  342. mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPT $1 > $2
  343. return 0
  344. }
  345.  
  346. # Compression function
  347. SUFFIX=""
  348. compression () {
  349. if [ "$COMP" = "gzip" ]; then
  350.     gzip -f "$1"
  351.     echo
  352.     echo Backup Information for "$1"
  353.     gzip -l "$1.gz"
  354.     SUFFIX=".gz"
  355. elif [ "$COMP" = "bzip2" ]; then
  356.     echo Compression information for "$1.bz2"
  357.     bzip2 -f -v $1 2>&1
  358.     SUFFIX=".bz2"
  359. else
  360.     echo "No compression option set, check advanced settings"
  361. fi
  362. return 0
  363. }
  364.  
  365.  
  366. # Run command before we begin
  367. if [ "$PREBACKUP" ]
  368.     then
  369.     echo ==================================================  ====================
  370.     echo "Prebackup command output."
  371.     echo
  372.     eval $PREBACKUP
  373.     echo
  374.     echo ==================================================  ====================
  375.     echo
  376. fi
  377.  
  378.  
  379. if [ "$SEPDIR" = "yes" ]; then # Check if CREATE DATABSE should be included in Dump
  380.     if [ "$CREATE_DATABASE" = "no" ]; then
  381.         OPT="$OPT --no-create-db"
  382.     else
  383.         OPT="$OPT --databases"
  384.     fi
  385. else
  386.     OPT="$OPT --databases"
  387. fi
  388.  
  389. # Hostname for LOG information
  390. if [ "$DBHOST" = "localhost" ]; then
  391.     HOST=`hostname`
  392. else
  393.     HOST=$DBHOST
  394. fi
  395.  
  396. # If backing up all DBs on the server
  397. if [ "$DBNAMES" = "all" ]; then
  398.         DBNAMES="`mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST --batch --skip-column-names -e "show databases"| sed 's/ /%/g'`"
  399.  
  400.     # If DBs are excluded
  401.     for exclude in $DBEXCLUDE
  402.     do
  403.         DBNAMES=`echo $DBNAMES | sed "s/b$excludeb//g"`
  404.     done
  405.  
  406.         MDBNAMES=$DBNAMES
  407. fi
  408.    
  409. echo ==================================================  ====================
  410. echo AutoMySQLBackup VER $VER
  411. echo http://sourceforge.net/projects/automysqlbackup/
  412. echo Backup of Database Server - $HOST
  413. echo ==================================================  ====================
  414.  
  415. # Test is seperate DB backups are required
  416. if [ "$SEPDIR" = "yes" ]; then
  417. echo Backup Start Time `date`
  418. echo ==================================================  ====================
  419.     # Monthly Full Backup of all Databases
  420.     if [ $DOM = "01" ]; then
  421.         for MDB in $MDBNAMES
  422.         do
  423.  
  424.              # Prepare $DB for using
  425.                 MDB="`echo $MDB | sed 's/%/ /g'`"
  426.  
  427.             if [ ! -e "$BACKUPDIR/monthly/$MDB" ]      # Check Monthly DB Directory exists.
  428.             then
  429.                 mkdir -p "$BACKUPDIR/monthly/$MDB"
  430.             fi
  431.             echo Monthly Backup of $MDB...
  432.                 dbdump "$MDB" "$BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.sql"
  433.                 compression "$BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.sql"
  434.                 BACKUPFILES="$BACKUPFILES $BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.sql$SUFFIX"
  435.             echo ----------------------------------------------------------------------
  436.         done
  437.     fi
  438.  
  439.     for DB in $DBNAMES
  440.     do
  441.     # Prepare $DB for using
  442.     DB="`echo $DB | sed 's/%/ /g'`"
  443.    
  444.     # Create Seperate directory for each DB
  445.     if [ ! -e "$BACKUPDIR/daily/$DB" ]    # Check Daily DB Directory exists.
  446.         then
  447.         mkdir -p "$BACKUPDIR/daily/$DB"
  448.     fi
  449.    
  450.     if [ ! -e "$BACKUPDIR/weekly/$DB" ]  # Check Weekly DB Directory exists.
  451.         then
  452.         mkdir -p "$BACKUPDIR/weekly/$DB"
  453.     fi
  454.    
  455.     # Weekly Backup
  456.     if [ $DNOW = $DOWEEKLY ]; then
  457.         echo Weekly Backup of Database ( $DB )
  458.         echo Rotating 5 weeks Backups...
  459.             if [ "$W" -le 05 ];then
  460.                 REMW=`expr 48 + $W`
  461.             elif [ "$W" -lt 15 ];then
  462.                 REMW=0`expr $W - 5`
  463.             else
  464.                 REMW=`expr $W - 5`
  465.             fi
  466.         eval rm -fv "$BACKUPDIR/weekly/$DB/week.$REMW.*"
  467.         echo
  468.             dbdump "$DB" "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql"
  469.             compression "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql"
  470.             BACKUPFILES="$BACKUPFILES $BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql$SUFFIX"
  471.         echo ----------------------------------------------------------------------
  472.    
  473.     # Daily Backup
  474.     else
  475.         echo Daily Backup of Database ( $DB )
  476.         echo Rotating last weeks Backup...
  477.         eval rm -fv "$BACKUPDIR/daily/$DB/*.$DOW.sql.*"
  478.         echo
  479.             dbdump "$DB" "$BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.sql"
  480.             compression "$BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.sql"
  481.             BACKUPFILES="$BACKUPFILES $BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.sql$SUFFIX"
  482.         echo ----------------------------------------------------------------------
  483.     fi
  484.     done
  485. echo Backup End `date`
  486. echo ==================================================  ====================
  487.  
  488.  
  489. else # One backup file for all DBs
  490. echo Backup Start `date`
  491. echo ==================================================  ====================
  492.     # Monthly Full Backup of all Databases
  493.     if [ $DOM = "01" ]; then
  494.         echo Monthly full Backup of ( $MDBNAMES )...
  495.             dbdump "$MDBNAMES" "$BACKUPDIR/monthly/$DATE.$M.all-databases.sql"
  496.             compression "$BACKUPDIR/monthly/$DATE.$M.all-databases.sql"
  497.             BACKUPFILES="$BACKUPFILES $BACKUPDIR/monthly/$DATE.$M.all-databases.sql$SUFFIX"
  498.         echo ----------------------------------------------------------------------
  499.     fi
  500.  
  501.     # Weekly Backup
  502.     if [ $DNOW = $DOWEEKLY ]; then
  503.         echo Weekly Backup of Databases ( $DBNAMES )
  504.         echo
  505.         echo Rotating 5 weeks Backups...
  506.             if [ "$W" -le 05 ];then
  507.                 REMW=`expr 48 + $W`
  508.             elif [ "$W" -lt 15 ];then
  509.                 REMW=0`expr $W - 5`
  510.             else
  511.                 REMW=`expr $W - 5`
  512.             fi
  513.         eval rm -fv "$BACKUPDIR/weekly/week.$REMW.*"
  514.         echo
  515.             dbdump "$DBNAMES" "$BACKUPDIR/weekly/week.$W.$DATE.sql"
  516.             compression "$BACKUPDIR/weekly/week.$W.$DATE.sql"
  517.             BACKUPFILES="$BACKUPFILES $BACKUPDIR/weekly/week.$W.$DATE.sql$SUFFIX"
  518.         echo ----------------------------------------------------------------------
  519.        
  520.     # Daily Backup
  521.     else
  522.         echo Daily Backup of Databases ( $DBNAMES )
  523.         echo
  524.         echo Rotating last weeks Backup...
  525.         eval rm -fv "$BACKUPDIR/daily/*.$DOW.sql.*"
  526.         echo
  527.             dbdump "$DBNAMES" "$BACKUPDIR/daily/$DATE.$DOW.sql"
  528.             compression "$BACKUPDIR/daily/$DATE.$DOW.sql"
  529.             BACKUPFILES="$BACKUPFILES $BACKUPDIR/daily/$DATE.$DOW.sql$SUFFIX"
  530.         echo ----------------------------------------------------------------------
  531.     fi
  532. echo Backup End Time `date`
  533. echo ==================================================  ====================
  534. fi
  535. echo Total disk space used for backup storage..
  536. echo Size - Location
  537. echo `du -hs "$BACKUPDIR"`
  538. echo ==================================================  ====================
  539. echo If you find AutoMySQLBackup valuable please make a donation at
  540. echo http://sourceforge.net/project/project_donations.php?group_id=101066
  541. echo ==================================================  ====================
  542.  
  543. # Run command when we're done
  544. if [ "$POSTBACKUP" ]
  545.     then
  546.     echo ==================================================  ====================
  547.     echo "Postbackup command output."
  548.     echo
  549.     eval $POSTBACKUP
  550.     echo
  551.     echo ==================================================  ====================
  552. fi
  553.  
  554. #Clean up IO redirection
  555. exec 1>&6 6>&-      # Restore stdout and close file descriptor #6.
  556.  
  557. if [ "$MAILCONTENT" = "files" ]
  558. then
  559.     #Get backup size
  560.     ATTSIZE=`du -c $BACKUPFILES | grep "[[:digit:][:space:]]total$" |sed s/s*total//`
  561.     if [ $MAXATTSIZE -ge $ATTSIZE ]
  562.     then
  563.         BACKUPFILES=`echo "$BACKUPFILES" | sed -e "s# # -a #g"#enable multiple attachments
  564.         cat $BACKUPFILES | mail -s "MySQL Backup Log and SQL Files for $HOST - $DATE"  $MAILADDR        #send via mutt
  565.     else
  566.         cat "$LOGFILE" | mail -s "WARNING! - MySQL Backup exceeds set maximum attachment size on $HOST - $DATE" $MAILADDR
  567.     fi
  568.  
  569. elif [ "$MAILCONTENT" = "log" ]
  570. then
  571.     cat "$LOGFILE" | mail -s "MySQL Backup Log for $HOST - $DATE" $MAILADDR
  572. else
  573.     cat "$LOGFILE"
  574. fi
  575.  
  576. # Clean up Logfile
  577. eval rm -f "$LOGFILE"
  578.  
  579. exit 0

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesServer Administration > Cron job: need to replace mutt command, need assistance


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek