LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-07-2003, 01:56 PM   #1
KungFuHamster
Member
 
Registered: Feb 2003
Location: Middle of frickin' nowhere
Distribution: The One True Distro
Posts: 230

Rep: Reputation: 30
Backup Script Tweaking and Debugging


After a near-disastrous incident with a recent power outage and a large ResierFS partition, I decided to write a handy-dandy backup script to prevent all my stuff from being wiped out. So here's what I've come up with after a bit of digging through some Linux reference books:

And yes, I do know it's ugly as sin.

Code:
#!/bin/sh
#Simple backup script for a few important things

#mount the backup drive and other necessary drives
echo 'Mounting necessary volumes...'
mount /dev/hdd /mnt/backup
mount /boot
echo 'Done'

#set the date for backup names
D='date +"%Y%m%d"'

#copy the necessary files and dirs for backup
echo 'Copying files marked for backup...'
cp -p /usr/src/linux/.config /mnt/backup/tmp
cp -pr /var/cache/edb/ /mnt/backup/tmp
cp -pr /home/neo/ /mnt/backup/tmp
cp -pr /etc/ /mnt/backup/tmp
cp -pr /root/ /mnt/backup/tmp
cp -pr /boot/ /mnt/backup/tmp
echo 'Done'

#compress the tmp dir into a tarball
echo 'Creating tarball now...'
tar cpzf /mnt/backup/system_$D.tgz /mnt/backup/tmp/*
echo 'Done'

#delete the contents of /mnt/backup/tmp
echo 'Cleaning up...'
rm -rf /mnt/backup/tmp/*
echo 'Done'

#unmount the previously mounted drives
echo 'Unmounting drives...'
umount /dev/hdd
umount /boot
echo 'Done'

#...and I'm spent
echo 'Your system is now fully backed up. Hooray!'
Here's the problems I'm currently having:

1. The script refuses to attach the date to the filename. The tarball should be "system_20031207.tgz", however it ends up being "system_date". How can I fix this?

2. What options do I need to give cp to preserve the directories? I want to simply be able to untar the latest backup from my root directory and be ready to go.

3. I've got another Gentoo box I use as a file server. How do I tell the script to automatically upload the latest backup to the server?

4. These backups are likely to take up a lot of space. How can I tell the script to delete older backups?

Any advice, or suggestions on how to improve it, would be greatly appreciated.
 
Old 12-07-2003, 02:30 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
1.) Use ` instead of ' :}

Cheers,
Tink
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Debugging and Linux Kernel Debugging Igor007 Programming 0 09-30-2005 10:33 AM
backup script nitaish Linux - General 1 04-22-2005 11:31 AM
debugging configure script Avatar33 Programming 3 03-23-2005 04:35 PM
Need a backup script enygma Linux - General 5 11-04-2004 03:49 PM
backup script ixion Linux - Software 2 01-09-2003 06:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration