Koozali.org: home of the SME Server

Backupscript for CD/DVD

pippin

Backupscript for CD/DVD
« on: December 19, 2006, 02:37:34 PM »
Here is a script i found on the net i will test it later with CD/DVD using two CD Green/Red

#!/bin/bash
#  backup
#------------------------------------------------------------------------------
#  Script to enable easy backup of all important Linux files
#  and also creates a customized system repair disk.
#  Uses two CD-RW Disks labled "RED" and "GREEN to rotate backups
#------------------------------------------------------------------------------
# The backup directory already contains files for boot and recovery.
# One can add more - my Slackware 8.1 system backup is < 580MB.

Backup_Dirs="/home /etc /usr/local /opt /var /root /boot"
Backup_Dest_Dir=/tmp/backup
Backup_Date=`date +%b%d%Y`
Image_File=/tmp/backup.iso
declare -i Size

# Create tar file with todays Month Day Year prepended for easy identification
tar cvzf $Backup_Dest_Dir/$Backup_Date.tar.gz $Backup_Dirs &> /dev/null

# Start backup process to local CD-RW drive
echo "Backing up $Backup_Dest_Dir to CD-RW Drive - $Backup_Date"
echo "Creating ISO9660 file system image ($Image_File)."

mkisofs -b toms288.img -c boot.cat -r \
        -o $Image_File $Backup_Dest_Dir  &> /dev/nul

# Check size of directory to burn in MB
Size=`du -m $Image_File | cut -c 1-3`
if [ $Size -lt 650 ]
then
   echo "Size of ISO Image $Size MB, OK to Burn"
else
   echo "Size of ISO Backup Image too Large to burn"
   rm $Backup_Dest_Dir/$Backup_Date.tar.gz # Remove dated tar file
   rm $Image_File   # ISO is overwritten next backup but cleanup anyway
   exit 1
fi

# Burn the CD-RW
Speed=4                 # Use best speed for CD-RW disks on YOUR system
echo "Burning the disk."
                              # Set dev=x,x,x from cdrecord -scanbus
cdrecord -v speed=$Speed blank=fast dev=1,0,0 $Image_File &> /dev/null
Md5sum_Iso=`md5sum $Image_File`
echo "The md5sum of the created ISO is $Md5sum_Iso"

# Could TEST here using Md5sum_Iso to verify md5sums but problem is tricky.
echo "To verify use script md5scd, this will produce the burned CD's md5sum"
echo "run this as User with backup CD in drive to be used for recovery."
echo "This verifies not only the md5sum but that disk will read OK when needed."

# Remove image file and tar file
echo "Removing $Image_File"
rm $Image_File
echo "Removing : $Backup_Dest_Dir/$Backup_Date.tar.gz"
rm $Backup_Dest_Dir/$Backup_Date.tar.gz
echo "END BACKUP $Backup_Date"
echo "Be sure to place this backup in the RED CD case and previous CD in GREEN"
echo "------------------------------------------------------------------------"
exit 0

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Backupscript for CD/DVD
« Reply #1 on: January 19, 2007, 10:08:57 PM »
pippin.

Any further word on success on this?

Thanks

Bob
If you think you know whats going on, you obviously have no idea whats going on!

pippin

Backupscript for CD/DVD
« Reply #2 on: January 20, 2007, 07:03:47 PM »
I cant make it to work

Offline Gaston94

  • ****
  • 184
  • +0/-0
Backupscript for CD/DVD
« Reply #3 on: January 20, 2007, 10:04:56 PM »
and did you look at the mondo rescue contrib ?
Unless I am wrong it should perform all of this perfectly
G.

pippin

Backupscript for CD/DVD
« Reply #4 on: January 21, 2007, 01:14:08 AM »
Quote from: "Gaston94"
and did you look at the mondo rescue contrib ?
Unless I am wrong it should perform all of this perfectly
G.
Yes i looked at the mondo rescue but as far as i know it doesnt support RAID so i guess its worthless making a image that doesnt work

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Backupscript for CD/DVD
« Reply #5 on: January 21, 2007, 02:46:06 AM »
pippin,

I am playing with the script, and have part of it working. At the moment the server I am working on does not have a CD-RW in it. Tomorrow it will. At the moment I have it creating the tar file. I am not going to be creating a bootable cd, because I want this only to back up some ibays.

I will post the modified script when I have it compleated.

Bob
If you think you know whats going on, you obviously have no idea whats going on!

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Backupscript for CD/DVD
« Reply #6 on: January 21, 2007, 10:36:40 PM »
pippin,

I have the script modified and working. I am using it with an IDE CD-RW, and backing up only /home and all it's sub-directories.
You will need to create a backup folder in your /tmp directory

mkdir -p /tmp/backup

You may need to adjust your CD-RW device number based on the result of cdrecord -scanbus
This script should be useful for a server in a small office where there is not a huge amount of data. It would not be hard to modify it to use re-writable DVD media.
Be careful how much data you re trying to save, it limits you to 580MB.
I set it up to open the tray when complete so the office staff will know it done.
I need to look at sending a message to a “key operator” if an error occurs.

I tried to set the directory to backup to “/home/e-smith/files/ibays”, and it did not like it. It sees the “-” as some sort of delimiter, and it chokes on it.

Here is the modified script

-----------cut---------------------
#!/bin/bash
# backup
#------------------------------------------------------------------------------
# Script to enable easy backup some important users files
# Uses multiple CD-RW Disks to rotate backups
# Original script by Alan Keates, and was found at
# http://www.faqs.org/docs/gazette/backup.html
#------------------------------------------------------------------------------
# The original backup directory contained files for boot and recovery,.
# These have been removed
# I plan on using this script in SME servers placed in small offices, where small sets of data require
# backup

Backup_Dirs="/home"
Backup_Dest_Dir=/tmp/backup
Backup_Date=`date +%b%d%Y`
Image_File=/tmp/backup.iso
declare -i Size

# Create tar file with todays Month Day Year prepended for easy identification
tar cvzf $Backup_Dest_Dir/$Backup_Date.tar.gz $Backup_Dirs &> /dev/null
# Start backup process to local CD-RW drive
echo "Backing up $Backup_Dest_Dir to CD-RW Drive - $Backup_Date"
echo "Creating ISO9660 file system image ($Image_File)."

mkisofs -o $Image_File $Backup_Dest_Dir

# Check size of directory to burn in MB
Size=`du -m $Image_File | cut -c 1-3`
if [ $Size -lt 650 ]
then
echo "Size of ISO Image $Size MB, OK to Burn"
else
echo "Size of ISO Backup Image too Large to burn"
rm $Backup_Dest_Dir/$Backup_Date.tar.gz # Remove dated tar file
rm $Image_File # ISO is overwritten next backup but cleanup anyway
exit 1
fi

# Burn the CD-RW
# Use best speed for CD-RW disks on YOUR system
echo "Burning the disk."
# Set dev=x,x,x from cdrecord -scanbus
cdrecord -v -eject speed=4 --dev=ATA:1,0,0 --blank=fast $Image_File &> /dev/null
Md5sum_Iso=`md5sum $Image_File`
echo "The md5sum of the created ISO is $Md5sum_Iso"

# Could TEST here using Md5sum_Iso to verify md5sums but problem is tricky.
echo "To verify use script md5scd, this will produce the burned CD's md5sum"
echo "run this as User with backup CD in drive to be used for recovery."
echo "This verifies not only the md5sum but that disk will read OK when needed."

# Remove image file and tar file
echo "Removing $Image_File"
rm $Image_File
echo "Removing : $Backup_Dest_Dir/$Backup_Date.tar.gz"
rm $Backup_Dest_Dir/$Backup_Date.tar.gz
echo "END BACKUP $Backup_Date"
echo "Be sure to place this backup in the RED CD case and previous CD in GREEN"
echo "------------------------------------------------------------------------"
exit 0
-------------------cut---------------------

Bob
If you think you know whats going on, you obviously have no idea whats going on!

Offline JonB

  • *
  • 351
  • +0/-0
Backupscript for CD/DVD
« Reply #7 on: January 22, 2007, 02:01:40 AM »
If you want to burn DVD's replace

Code: [Select]
cdrecord -v -eject speed=4 --dev=ATA:1,0,0 --blank=fast $Image_File &> /dev/null

with

Code: [Select]
growisofs -dvd-compat -Z /dev/cdrom -use-the-force-luke -R -J $Image_File &> /dev/null

This will burn +RW and -RW DVD's. The DVD's are blanked each time and ejected after burning.

You will have to modify the part of the script that checks the image size to take into account the increased size of the DVD.

Jon
...

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Backupscript for CD/DVD
« Reply #8 on: January 22, 2007, 02:16:54 AM »
Thanks JonB. That may prove helpful in the furture.

Bob
If you think you know whats going on, you obviously have no idea whats going on!

addodge

Backupscript for CD/DVD
« Reply #9 on: January 22, 2007, 03:54:42 AM »
Can you tell us that are fairly new to sme how to take that script from here and implement it into a server?
Thanks

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Backupscript for CD/DVD
« Reply #10 on: January 22, 2007, 04:12:44 AM »
Give me a couple of days and I will write a detailed "How To".

Bob
If you think you know whats going on, you obviously have no idea whats going on!

pippin

Backupscript for CD/DVD
« Reply #11 on: February 02, 2007, 07:43:04 PM »
I am testing this script now using dvd-r and so far it looks like it works.
Thanks crazybob :D

Offline Jáder

  • *
  • 1,099
  • +0/-0
    • LinuxFacil
problem ... writing just .iso file not iso content
« Reply #12 on: July 27, 2007, 03:15:07 AM »
Hi guys,

I'm using the script, but I have a problem.
When writing it just write the .iso file... not the ISO content.

I just commented out the mkisofs line and inserted the growisofs line as recommended.

Any ideas why ?

BTW: I try to change growisofs line to:
growisofs -dvd-compat -Z /dev/cdrom=$Image_File -use-the-force-luke -R -J  &> /dev/null
[

Moved the $Image_file to after device line and put a = signal as seen on so many web sites.
...

Offline psoren

  • *
  • 371
  • +0/-0
Re: problem ... writing just .iso file not iso content
« Reply #13 on: February 13, 2008, 11:18:26 PM »
Hi guys,

I'm using the script, but I have a problem.
When writing it just write the .iso file... not the ISO content.

I just commented out the mkisofs line and inserted the growisofs line as recommended.

Any ideas why ?

This line means "put the file on the DVD":
growisofs -dvd-compat -Z /dev/cdrom -use-the-force-luke -R -J $Image_File &> /dev/null

And this means "MAKE a DVD of the file":
growisofs -dvd-compat -Z /dev/cdrom=$Image_File


I Have the script working now with DVD-R, i can for some reason not get it to blank my DVD+RW. It could be the media. But main thing is, it's working.

Per

UPDATE: It was for some reason the media. I tried with a DVD-RW and it works fine.
« Last Edit: February 17, 2008, 11:27:14 AM by psoren »

Offline Jáder

  • *
  • 1,099
  • +0/-0
    • LinuxFacil
Re: Backupscript for CD/DVD
« Reply #14 on: February 17, 2008, 03:54:09 PM »
This line means "put the file on the DVD":
growisofs -dvd-compat -Z /dev/cdrom -use-the-force-luke -R -J $Image_File &> /dev/null

And this means "MAKE a DVD of the file":
growisofs -dvd-compat -Z /dev/cdrom=$Image_File

Thanks by the info. This did the trick.
Jáder
...