?
Solved

Linux Shell Script Challenge

Posted on 2007-03-28
2
Medium Priority
?
360 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 1800 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 200 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

752 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