Solved

Linux Shell Script Challenge

Posted on 2007-03-28
2
345 Views
Last Modified: 2013-12-16
I am in a time crunch so am asking for as much guidance or samples as possible to accomplish the following in a shell script.

On an Ubuntu Edgy Eft server, do:

1. Stop Apache
2. Stop MySQL
3. tgz all files in webroot and date the archive (e.g. webrootbackup03282007.tgz)
4. tgz all MySQL databases and date the archive (e.g. mysqlbackup03282007.sql..tgz)
5. Start MySQL
6. Start Apache
7. Ship the archives to a Windows Server NTFS share
8. Delete the "local" copies of tgz's.
9. Email me a report

(I will then set cron to run the script as necessary...)
0
Comment
Question by:smetterd
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 450 total points
ID: 18808813
Would be something like:
(
 /etc/init.d/apache stop;
 /etc/init.d/mysql stop;
 DATE=`date "+%Y%m%d"`
 tar -czf /tmp/webrootbackup${DATE}.tgz /your/webroot
 tar -czf /tmp/mysqlbackup${DATE}.tgz /var/lib/mysql
 /etc/init.d/mysql start;
 /etc/init.d/apache start;
 smbmount //windows/share /mnt
 mv /tmp/webrootbackup${DATE}.tgz /tmp/mysqlbackup${DATE}.tgz /mnt
 smbumount /mnt
) | mail -s "backup report" you@example.com

Can't tell you if the pathe to the start-scripts are correct that way, only have a SuSE-box
0
 
LVL 25

Assisted Solution

by:Cyclops3590
Cyclops3590 earned 50 total points
ID: 18809069
hrnst42 pretty much nailed it;  however personally whenever stopping and restarting critical services, I'd put in extra checks on those in case an error happens
example, (provided the apache stop exits with an error code if it fails; like it should)
 /etc/init.d/apache stop || mail -s "apache stop error" you@example.com && exit 1

then you know where the script received an error and exits the script so not to potentially cause any problems with future commands.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now