Note that there are some explanatory texts on larger screens.

plurals
  1. POError Handling For A Mac/UNIX Shell Script to Backup Our Web Servers and MySQL Databases
    primarykey
    data
    text
    <p>I wrote myself a shell script to backup our web servers and got it working. It navigates to the backup directory, does an rsync, a mysqldump, commits it all to a git repository for versioning and pushes it to our remote git server. I've learned that there's lots of pitfalls to writing scheduled UNIX scripts, so I'm wondering if I'm missing anything or setting myself up for disaster. How would I have it email me on any error in the entire process?</p> <pre><code>#!/bin/bash #Exit on any error set -e LOGFILE=~/backups/web_backup-$(date +"%m.%d.%Y_%H.%M.%S").log touch $LOGFILE echo "Backup started for "$(date +"%m.%d.%Y_%H.%M.%S") | tee -a $LOGFILE ############################################################ ###### BACKUP WEBSITE ############################################################ echo "Backing up Website..." 2&gt;&amp;1 | tee -a $LOGFILE cd ~/backups/example.org if [ "$?" != "0" ]; then echo "Cannot change directory!" 1&gt;&amp;2 exit 1 fi rsync -Pav --size-only --delete --filter='P .git' --filter='P example.com.sql' backups@example.com:/path/to/example.org/ ~/backups/example.org/ 2&gt;&amp;1 | tee -a $LOGFILE echo "Backing up Example.com DB..." 2&gt;&amp;1 | tee -a $LOGFILE ssh backups@example.com "mysqldump -u user -hlocalhost -ppassword dbname &gt; example.com.sql echo "Adding files to Git Repository..." 2&gt;&amp;1 | tee -a $LOGFILE git add . 2&gt;&amp;1 | tee -a $LOGFILE| tee -a $LOGFILE echo "Commiting files to Git Repository..." 2&gt;&amp;1 | tee -a $LOGFILE git commit -m "Backup as of "$(date +"%m.%d.%Y_%H.%M.%S") 2&gt;&amp;1 | tee -a $LOGFILE echo "Pusing Git Repo to Remote Location..." 2&gt;&amp;1 | tee -a $LOGFILE git push origin master 2&gt;&amp;1 | tee -a $LOGFILE echo "Finished backing up Website..." 2&gt;&amp;1 | tee -a $LOGFILE echo "Backup Finished for "$(date +"%m.%d.%Y_%H.%M.%S") exit </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload