Shell script help (Not sure if this should be in Linux forum)

Associate
Joined
22 May 2011
Posts
1,445
Location
Edinburgh
Hey all, basically I'm trying to write a script to backup some files in seperate folders dependant on file type.

So if I have word files, spreadsheets and jpegs i end up with thusly named folders inside them.

each folder has 3 pieces of test data in it to ensure the cp actually works. It does.
What is killing me is that if I run the backup for say the JPEG folder I get:

/home/USER/files/JPEGs(where the three pieces of data are) pic1, pic2, pic3

My backup folder looks like:

/home/USER/backup/JPEGs pic1, pic2, pic3

If I delete say pic2 then re-run the backup I get this:

/home/USER/backup/JPEGs JPEGS(a dir with all 3 pics inside) pic1 pic3.

I'm using copy with -r which as far as I am aware would just replace the missing picture yet for some crazy reason it copys the entire dir into the dir where the pictures are!


I realise this makes little sense.... My brain is fried and this is annoying me, please help.
 
This is everything so far:

Code:
echo "----- Backup/Restore Utility ------"
echo "---- Created by Sean Johnstone ----"
echo "-----------------------------------"
echo "|                                 |"
echo "|     Please select an option:    |"
echo "|                                 |"
echo "| 1) Backup all 3 folders         |"
echo "| 2) Backup WP folder             |"
echo "| 3) Backup XLS folder            |"
echo "| 4) Backup JPEG folder           |"
echo "|                                 |"
echo "| 5) Restore all 3 folders        |"
echo "| 6) Restore WP folder            |"
echo "| 7) Restore XLS folder           |"
echo "| 8) Restore JPEG folder          |"
echo "-----------------------------------"
echo ""

read input

case $input in
1) echo "Backing Up all folders..."  
   cp -r /home/sean/work/WPS/ ~/BACKUP2/WPS/	
   cp -r /home/sean/work/XLS/ ~/BACKUP2/XLS/
   cp -r /home/sean/work/JPEGS/ ~/BACKUP2/JPEGS/
   echo "Done!";;

2) echo "Backing up Word Processing folder..."  
   cp -r /home/sean/work/WPS/ ~/BACKUP2/WPS/
   echo "Done!";;

3) echo "Backing up Spreadsheet folder..." 
   cp -r /home/sean/work/XLS/ ~/BACKUP2/XLS/
   echo "Done!";;

4) echo "Backing up JPEG folder..." 
   cp -r /home/sean/work/JPEGS/ ~/BACKUP2/JPEGS/
   echo "Done!";;
esac
 
Yay it works! Although from the look of my directory it is just plain overwriting :/

I thought the recursive rule prevents this?

EDIT: Oh wait I would want it to do this wouldn't I if I was backing up XD

Although I would only want say a missing file to be restored? Is there anyway to do this?
 
Sorted that. doing cp -rnu fixed it :)

Although I've discovered that if I restore before I backup it just hangs. What would be the code to check if the dir exists? and if not make one?

Sorry if I seem a bit annoying I'm new to this :P
 
Back
Top Bottom