Koozali.org: home of the SME Server

A little scripting help

Offline Stuart

  • *
  • 37
  • +0/-0
A little scripting help
« on: May 14, 2008, 07:37:09 AM »
Please be kind, I have had a backup script working but recently have encountered no end of trouble.  The script was made as per the help I had in this thread .... http://forums.contribs.org/index.php?topic=40625.0

The current script...
Code: [Select]
#!/bin/sh
signal-event pre-backup
cd /
tar czf /home/e-smith/files/ibays/backup/files/smeserver.tgz `perl -e 'use esmith::Backup; $b=new esmith::Backup; print join("\n",$b->restore_list)'` --exclude='home/e-smith/files/ibays/backup/files/smeserver.tgz'
signal-event post-backup

Results in the following...
Can't open directory /etc/e-smith/events/pre-backup
desktop_backup.sh: line 3: cd: /
: No such file or directory
tar: /home/e-smith/files/ibays/backup/files/smeserver.tgz: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: home/e-smith: Cannot stat: No such file or directory
tar: etc/e-smith/templates-custom: Cannot stat: No such file or directory
tar: etc/e-smith/templates-user-custom: Cannot stat: No such file or directory
tar: etc/ssh: Cannot stat: No such file or directory
tar: root: Cannot stat: No such file or directory
tar: etc/sudoers: Cannot stat: No such file or directory
tar: etc/passwd: Cannot stat: No such file or directory
tar: etc/shadow: Cannot stat: No such file or directory
tar: etc/group: Cannot stat: No such file or directory
tar: etc/gshadow: Cannot stat: No such file or directory
tar: etc/samba/secrets.tdb: Cannot stat: No such file or directory
tar: etc/samba/smbpasswd: Cannot stat: No such file or directory
tar: etc/smbpasswd: Cannot stat: No such file or directory


I have played around with this to no end, but can only seem to produce different errors.

As always, what am I missing?

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: A little scripting help
« Reply #1 on: May 14, 2008, 05:11:28 PM »
Did you try some sort of restore? I find it hard to imagine that a backup leads to problems like this as it seems you cannot cd to the root (cd /) of your file system.

The backup command works perfectly on my system if I create a backup ibay.

What user is executing the script? Can you access the root as that user form the SME Server shell?
« Last Edit: May 14, 2008, 05:20:55 PM by cactus »
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline dmay

  • *
  • 450
  • +0/-0
    • http://myezserver.com
Re: A little scripting help
« Reply #2 on: May 14, 2008, 07:09:46 PM »
Looks to be an ownership/rights issues when the script is executed, which leads me to ask, how are you executing the script?

Next, why bother with such a script when backup contribs are available?

Darrell

Offline Stuart

  • *
  • 37
  • +0/-0
Re: A little scripting help
« Reply #3 on: May 15, 2008, 12:43:30 AM »
Guys, I am trying to run this logged in as root using the command
sh dbackup.sh

The idea is to put it in Cron.daily, the resulting tarball is collected by the backup server.
If you look at the output it is actually failing on the first line, which probably is causing the cd / to be sent incorrectly.

Next, why bother with such a script when backup contribs are available?
Seems like a simple easy solution that suits our setup.

Offline dmay

  • *
  • 450
  • +0/-0
    • http://myezserver.com
Re: A little scripting help
« Reply #4 on: May 15, 2008, 07:50:15 PM »
which probably is causing the cd / to be sent incorrectly.

Set the root directory as a persistent variable in your script:

ROOTDIR=/
cd $ROOTDIR

Darrell

Offline Stuart

  • *
  • 37
  • +0/-0
Re: A little scripting help
« Reply #5 on: May 16, 2008, 12:36:11 AM »
Thanks but the script actually fails on the first line

signal-event pre-backup

as evidenced by the output

Can't open directory /etc/e-smith/events/pre-backup

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: A little scripting help
« Reply #6 on: May 16, 2008, 12:36:09 PM »
Thanks but the script actually fails on the first line

signal-event pre-backup

as evidenced by the output

Can't open directory /etc/e-smith/events/pre-backup
Then you are doing something seriously wrong or you system is messed up. I did the following and it worked like a charm:

Logged in as root

nano /tmp/test.sh

copied the code you suggested in there

Ctrl+X, Y to save

chmod +x /tmp/test.sh

/tmp/test.sh

The script ran error free and the created archive contains the folders and files it should hold.

Please see if you can reproduce the error following above scheme, as I did.
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline Stuart

  • *
  • 37
  • +0/-0
Re: A little scripting help
« Reply #7 on: May 19, 2008, 03:45:38 AM »
Fixed.

It appears the encoding of the file was getting messed up, although this was not apparent in pico.  I created a new script using nano and retyped the entire script and it now works perfectly.

@ cactus, thanks so much for running that on your system and proving that it should work.

Please see if you can reproduce the error following above scheme, as I did.
:D