Page 1 of 1

Backup script fails in Crontab (ubuntuserver 8.04/vbox 2.14)

Posted: 7. Aug 2009, 08:40
by thomasjohansen
Hi I have made a backup script which savestates my VDI's and then clones them to another location.

The script looks like this:

Code: Select all

#!/bin/sh

VBoxManage controlvm WebServer2 savestate&&
VBoxManage controlvm Mailserver savestate&&

rm /media/LaCie/Server-Backup/WebServer2-5.vdi&&
mv /media/LaCie/Server-Backup/WebServer2-4.vdi /media/LaCie/Server-Backup/WebServer2-5.vdi&&
mv /media/LaCie/Server-Backup/WebServer2-3.vdi /media/LaCie/Server-Backup/WebServer2-4.vdi&&
mv /media/LaCie/Server-Backup/WebServer2-2.vdi /media/LaCie/Server-Backup/WebServer2-3.vdi&&
mv /media/LaCie/Server-Backup/WebServer2-1.vdi /media/LaCie/Server-Backup/WebServer2-2.vdi&&
rm /media/LaCie/Server-Backup/mailserver-5.vdi&&
mv /media/LaCie/Server-Backup/mailserver-4.vdi /media/LaCie/Server-Backup/mailserver-5.vdi&&
mv /media/LaCie/Server-Backup/mailserver-3.vdi /media/LaCie/Server-Backup/mailserver-4.vdi&&
mv /media/LaCie/Server-Backup/mailserver-2.vdi /media/LaCie/Server-Backup/mailserver-3.vdi&&
mv /media/LaCie/Server-Backup/mailserver-1.vdi /media/LaCie/Server-Backup/mailserver-2.vdi&&

VBoxManage clonehd /home/thomas/.VirtualBox/VDI/WebServer2.vdi /media/LaCie/Server-Backup/WebServer2-1.vdi&&
VBoxManage clonehd /home/thomas/.VirtualBox/VDI/mailserver.vdi /media/LaCie/Server-Backup/mailserver-1.vdi&&

VBoxManage startvm WebServer2 -type vrdp&&
VBoxManage startvm WebServer2 -type vrdp&&

I know its nothing fancy, and there should have been some if's to catch errors but im not good at scripts yet.

When running the script manually it works fine and doing what its supposed to but when running it as a crontab job it fails.

I have added it to Cron like this:

Code: Select all

sudo crontab -e

Code: Select all

# m h  dom mon dow   command
0 1 * * * (/usr/bin/aptitude -y update && /usr/bin/aptitude -y safe-upgrade) 2$
0 2 * * * bash /home/thomas/Scripts/backup.sh 2>&1 >> /var/log/auto_backup.log
the log file after a crontab job gives this error:
VirtualBox Command Line Management Interface Version 2.1.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

WARNING! The following VirtualBox settings files have been automatically
converted to the new settings file format version '1.6-linux':

/root/.VirtualBox/VirtualBox.xml (1.3-linux)

The current command was aborted to prevent overwriting the above settings
files with the results of the auto-conversion without your permission.
Please put one of the following command line switches to the beginning of
the VBoxManage command line and repeat the command:

-convertSettings - to save all auto-converted files (it will not
be possible to use these settings files with an
older version of VirtualBox in the future);
-convertSettingsBackup - to create backup copies of the settings files in
the old format before saving them in the new format;
-convertSettingsIgnore - to not save the auto-converted settings files.

Note that if you use -convertSettingsIgnore, the auto-converted settings files
will be implicitly saved in the new format anyway once you change a setting or
start a virtual machine, but NO backup copies will be created in this case.


I find this strange since it works when running the script manually.

Anyone who has an idea on a solution for this?

Re: Backup script fails in Crontab (ubuntuserver 8.04/vbox 2.14)

Posted: 7. Aug 2009, 14:45
by baf
Do you usually run this guest machine as root?
If not then it should be in that users crontab not roots.
Remember each user can have his/her own machines.

Re: Backup script fails in Crontab (ubuntuserver 8.04/vbox 2.14)

Posted: 7. Aug 2009, 15:30
by thomasjohansen
thx for your fedback I'll look into it.


But yes the guests is placed in my user home dir not the root, but why is it trying to do it in the root folder?


should I define from where the VBoxmanage should run from?

like:

/home/thomas/.Virtualbox/VBoxManage controlvm WebServer2 savestate

Re: Backup script fails in Crontab (ubuntuserver 8.04/vbox 2.14)

Posted: 7. Aug 2009, 15:56
by baf
no you should run crontab -e without sudo if you use sudo you edit roots crontab.
Or possibly in roots crontab something like (untested):

Code: Select all

0 2 * * * su -c username "bash /home/thomas/Scripts/backup.sh 2>&1 >> /var/log/auto_backup.log"
Should work

Re: Backup script fails in Crontab (ubuntuserver 8.04/vbox 2.14)

Posted: 8. Aug 2009, 11:51
by thomasjohansen
thx for this valuable information. did not know that there was a difference by using sudo and not.

I'll try your suggestions on monday.