Register
It is currently Sun Aug 31, 2014 12:25 am

Help with automation script for Crossover Games backups.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Tue Apr 26, 2011 11:00 am   

Joined: Tue Apr 26, 2011 9:48 am
Posts: 4
OK, long story short, anyone who knows of Crossover Games/Office knows that if you have a large number of bottles, it can take a while to back them up using their GUI tools. They have some CLI tools too, which I was hoping to already be utilizing :D Basically the following "should" be going thru the dir, and tarring up each directory along with some extra metadata.

Code:
for bottle in ~/.cxgames/*
do
/opt/cxgames/bin/cxbottle --bottle "$bottle" --tar ~/cxgbackup/$bottle.cxarchive
done


Where my problem lies is simple, although the solution is completely eluding me. Basically, any bottle directory that has a space in it, the script will fail on that directory.

What shall I do here? I am lost on this one. In short I just want a nice way to archive them periodically for safekeeping, plus its a nice way to backup prior to an OS upgrade.

Thanks for any help.

Andrew.


Top
 Profile  
 PostPosted: Tue Apr 26, 2011 12:46 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
Hi,

Quote:
What shall I do here?

use more quote, and HOME instead of ~
Code:
for bottle in ~/.cxgames/*
do
/opt/cxgames/bin/cxbottle --bottle "$bottle" --tar "$HOME/cxgbackup/$bottle.cxarchive"
done


Top
 Profile  
 PostPosted: Wed Apr 27, 2011 6:52 am   

Joined: Tue Apr 26, 2011 9:48 am
Posts: 4
Unfortunately that doesn't work out for me. Ran into pathing and spacing errors still.

With some help from a guy from work who oddly is little better than me on this stuff, I managed to get to this:

Code:
mkdir $HOME/cxgbackup/

cd $HOME/.cxgames/

for bottle in ls -d */
do
bottlefixed=${bottle%/}
/opt/cxgames/bin/cxbottle --bottle "$bottlefixed" --tar "$bottlefixed.cxarchive"
done

mv $HOME/.cxgames/*.cxarchive $HOME/cxgbackup/


It mostly works. I still have some errors that crop up,

Code:
[andrew@asusg51 ~]$ sh ./Applications/cxgbackup.sh
mkdir: cannot create directory `/home/andrew/cxgbackup/': File exists
cxbottle:error: Unable to find the 'ls' bottle:
bottle 'ls' not found in '/home/andrew/.cxgames'
bottle 'ls' not found in '/opt/cxgames/support'
cxbottle:error: Unable to find the '-d' bottle:
bottle '-d' not found in '/home/andrew/.cxgames'
bottle '-d' not found in '/opt/cxgames/support'


I am sure that is from the interesting way to list the directories out. Any tips there would be great. I dunno if its just me or if it is -- but I think this is quite hacked together :D Any cleanup tips would be fantastic.

Thanks for your help,
Andrew.


Top
 Profile  
 PostPosted: Wed Apr 27, 2011 8:35 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
don't use ls to feed a for-loop, because a for-loop iterates on each element, and so it'll consider
my file
as two elements.
Code:
bak="$HOME/cxgbackup/"

# bak exists as a directory, or creates it
[ -d "$bak" ] || mkdir "$bak"

for directory in $HOME/.cxgames/*/
do /opt/cxgames/bin/cxbottle --bottle "$directory" --tar "$bak/${directory%/}.cxarchive"
done


Top
 Profile  
 PostPosted: Sun May 01, 2011 2:33 pm   

Joined: Tue Apr 26, 2011 9:48 am
Posts: 4
Thanks!

Sorry for the late reply. Got busy, then I had to test it. The directory I have is huge, with over 250GB of crap in there. So it did take a little while to finish up.

I am tweaking it a bit, but at the core, your repairs worked great, and you apparently have ESP. As you added in what I was about to get to, without me needing to ask :D

Thanks again,
I appreciate all the help here.

Andrew.


Top
 Profile  
 PostPosted: Mon May 02, 2011 7:54 am   

Joined: Tue Apr 26, 2011 9:48 am
Posts: 4
BTW, here is my nearly complete script. I never quite got the darn command to archive the bottle to actually archive it up in the .cxarchive format directly into the backup directory, as the path of existing bottle stayed with that, so it was all screwed up like

/home/andrew/cxgbackup//home/andrew/.cxgames/blah.cxarchive

Oh well, if you know of a simple way to fix that, cool, otherwise this method I have works fine.

Thanks again!

Code:
#!/bin/bash
##
## Crossover Bottle Mass Backup Utility -- Bash edition.
##
## Written by Andrew Schott (with help from bashscripts.org )
## Send any questions to andrew@schotty.com

## Set backup file directories.
CXGBACKUPDIR="$HOME/cxgbackup/"
CXOBACKUPDIR="$HOME/cxobackup/"

## Set default CX bottle directories.
CXGDIR="$HOME/.cxgames"
CXODIR="$HOME/.cxoffice"

## Create backup directories if they do not exist.
[ -d "$CXGBACKUPDIR" ] || mkdir "$CXGBACKUPDIR"
[ -d "$CXOBACKUPDIR" ] || mkdir "$CXOBACKUPDIR"

## Perform backup of .cxgames
for bottle in $CXGDIR/*/
do
if [[ "$bottle" = "$CXGDIR/desktopdata/" ]]
then echo Skipping $bottle as it is a CX directory/file
elif [[ "$bottle" = "$CXGDIR/installers/" ]]
  then echo Skipping $bottle as it is a CX directory/file
elif [[ "$bottle" = "$CXGDIR/tie/" ]]
  then echo Skipping $bottle as it is a CX directory/file
elif [[ "$bottle" = "$CXGDIR/cxgames.conf" ]]
  then echo Skipping $bottle as it is a CX directory/file
elif [[ "$bottle" = "$CXGDIR/usage.log" ]]
  then echo Skipping $bottle as it is a CX directory/file
else {
  echo Archiving $bottle
  /opt/cxgames/bin/cxbottle --bottle "$bottle" --tar "${bottle%/}.cxarchive"
  mv "${bottle%/}.cxarchive" "$CXGBACKUPDIR"
  echo Archival of $bottle completed and moved to $CXGBACKUPDIR
  }
fi
done

## Perform backup of .cxoffice
for bottle in $CXODIR/*/
do
if [[ "$bottle" = "$CXODIR/desktopdata/" ]]
then echo Skipping $bottle as it is a CX directory/file
elif [[ "$bottle" = "$CXODIR/installers/" ]]
  then echo Skipping $bottle as it is a CX directory/file
elif [[ "$bottle" = "$CXODIR/tie/" ]]
  then echo Skipping $bottle as it is a CX directory/file
elif [[ "$bottle" = "$CXODIR/cxoffice.conf" ]]
  then echo Skipping $bottle as it is a CX directory/file
elif [[ "$bottle" = "$CXODIR/usage.log" ]]
  then echo Skipping $bottle as it is a CX directory/file
else {
  echo Archiving $bottle
  /opt/cxoffice/bin/cxbottle --bottle "$bottle" --tar "${bottle%/}.cxarchive"
  mv "${bottle%/}.cxarchive" "$CXOBACKUPDIR"
  echo Archival of $bottle completed and moved to $CXOBACKUPDIR
  }
fi
done


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP