Backup script: Copying and removing directories based on list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Backup script: Copying and removing directories based on list
# 1  
Old 02-04-2010
Backup script: Copying and removing directories based on list

I am writing a simple backup script, but I cannot figure out how to remove directories that are found in a list. For example:
Code:
DONT_COPY="
.adobe/
.bin/google-earth
" 

tar -zcvf - * --exclude=$DONT_COPY | openssl des3 -salt -k $1 | dd of=$(hostname)-$(date +%Y%m%d).tbz > COPIED

Note that this example does not work, I need to translate the DONT_COPY list to a better format. How can I do that?

Later in the script I compare the list of items in COPIED to a DO_COPY list so that the user could examine them at his leisure and decide whether or not to include them in future backups.
# 2  
Old 02-04-2010
If on linux, you can either use --exclude-from and add the files to exclude into the file or you will have to use one --exclude for each pattern you want to exclude from tar.

Code:
$cat files_to_exclude
.adobe/
.bin/google-earth
$ tar -zcf --exclude-from=files_to_exclude file.tgz *

OR

Code:
$ tar -zcf --exclude=.adobe --exclude=bin/google-earth file.tgz *

# 3  
Old 02-04-2010
Thanks, agn. How can I treat the DONT_COPY variable as a file, or alternatively, can I expand it to add the --exclude= text before all entries?
# 4  
Old 02-04-2010
Try
Code:
$ for pattern in $DONT_COPY ; do echo -n "--exclude=$pattern "; done

# 5  
Old 02-04-2010
Thanks! I had to change that to write to a variable, as it is in a script:
Code:
DONT_COPY_LIST=""
for pattern in $DONT_COPY ; do DONT_COPY_LIST="$DONT_COPY_LIST --exclude=$pattern "; done

However, it fails on spaces. The linux-wife balance is greatly upset by demanding no spaces in filenames, so the DONT_COPY list looks more like this (sorry that I did not think of this earlier):
Code:
DONT_COPY="
.adobe/
File with Spaces
.bin/google-earth
Yet Another Annoying Filename
"

I tried replacing DONT_COPY in the second line with quotes, but this did not help (it created a different problem). How can I work with spaces in filenames?

I appreciate your patience and advice. I have googled this, but I can find no examples in which one is working with a list like this.

---------- Post updated at 11:30 PM ---------- Previous update was at 07:10 PM ----------

I got it with some help on a LUG mailing list:

Code:
EXCLUDES=`tempfile`
cat >$EXCLUDES <<EOLIST
$DONT_COPY
EOLIST

tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 | dd of=$(hostname)-$(date +%Y%m%d).tbz

rm -f $EXCLUDES

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying files to directories based on first 6 character

guys, i did create a script but its too long, though it function the same. # cat nightlyscan.sh #!/usr/ksh deyt=`date +"%Y-%m-%d"` for i in `ls -lrt|grep $deyt|awk '{print $9}'` do cp -f $i /S1/Sophos/logger/ done # but i did not paste it all. this is the desired. (9 Replies)
Discussion started by: kenshinhimura
9 Replies

2. Shell Programming and Scripting

Need help in finding and copying list of files using bash shell script

Dear All, I have a situation where I want to copy some files of type .txt. These files are o/p from one program. Some of the files are named as fileName .txt instead of fileName.txt after fileName by mistake I have specified "space". Now I want to move these files as follows. mv fileName*... (13 Replies)
Discussion started by: linuxUser_
13 Replies

3. Shell Programming and Scripting

Chose list of sub directories in a bash script file

Hi, I have a command in my bash script, searchDirectoryName.sh: DIR_NAME=$(find . -type d) echo "${DIR_NAME}" . ./Dir1 ./Dir1/1.0.2.1 ./Dir2 ./Dir2/1.1 ./Dir3 ./Dir3/2.2.1 How can I select only following directory names with second subdirectoies and without first ./ in the... (3 Replies)
Discussion started by: hce
3 Replies

4. Shell Programming and Scripting

Looping inside directories based on a file which contains file directory list

Hi All, Please help. I have got a file which contains a listing of a file and some directories after it, one by one. I am calling this file xyz.txt here file1 dir1 dir2 dir3 dir4 file2 dir5 dir6 dir7 dir8 file3 dir9 dir10 dir11 dir12 (6 Replies)
Discussion started by: Piyush Jakra
6 Replies

5. Shell Programming and Scripting

Removing and copying in shellscript

Hi, I need to edit an xml file as such <B="A"><!]></B> so that the output is <A><!]></A> This is a massive xml file and the A B and C are always different however the output should always be the same. Does anyone know any solution to this please? thanks in advance (2 Replies)
Discussion started by: legolad
2 Replies

6. Shell Programming and Scripting

Copying a files from a filter list and creating their associated parent directories

Hello all, I'm trying to copy all files within a specified directory to another location based on a find filter of mtime -1 (Solaris OS). The issue that I'm having is that in the destination directory, I want to retain the source directory structure while copying over only the files that have... (4 Replies)
Discussion started by: hunter55
4 Replies

7. Shell Programming and Scripting

a remove script taken in input a file which contain a list of directories

Hi, I'm looking to delete some files from directories. I've just put in a file the location of these files. e.g: in file supprs.txt there is: /usr/host/t1.txt /etc/dev/u1.java /home/new/files/view.c Is it possible to take this file "supprs.txt" as a parameter in a shell command ? (2 Replies)
Discussion started by: yeclota
2 Replies

8. UNIX for Dummies Questions & Answers

copying files from one location to another based on a list

I have a text list of about 3,000 file names (image files), which exist on a server and that I want to copy over to another location. I understand the Unix cp code, but what's the string to have it copy multiple files based on an external list? Many thanks! (4 Replies)
Discussion started by: rebornhonest
4 Replies

9. Shell Programming and Scripting

help with script to list directories

Hi All I have two scripts which i used to try and list all the directories one using 'function', which only lists the first directory and does not show directories within directories. function ListDir () { for arg in $(ls $HOME) do if then echo $arg ... (2 Replies)
Discussion started by: chassis
2 Replies

10. Shell Programming and Scripting

Script to list changes in Directories

Hello guys it's me again, I need some help. What I'm doing is listing all the file and directories Recusively and using it a a master file. Then I need to do the same the nest day to make sure nothing was deleted or modified. What happen is file in one of out major directories was deleted without... (2 Replies)
Discussion started by: aojmoj
2 Replies
Login or Register to Ask a Question