Solved

Linux Shell Script Challenge

Posted on 2007-03-28
2
343 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

760 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

21 Experts available now in Live!

Get 1:1 Help Now