bash script to copy files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script to copy files
# 1  
Old 04-06-2011
bash script to copy files

hey everyone, new here

i have arch setup and i am using smbnetfs to mount some windows shares in /mnt/smbnet

what i want to do is copy files from my home dir to a dir in /mnt/smbnet but i also need it to remove files if i have deleted them from my home dir

seems that cp would be the easiest for me, but i cant get it to remove a file from the dest that has been deleted from the source

example, i can do this as root
Code:
cp -pru /home/user/Videos/* /mnt/smbnet/share/Vids

and it does copy files. and if i add a file, it copies the new one over. but if i delete a file and run this command, the deleted file does not get removed from /mnt/smbnet

didnt see anything in man cp that relates to what i am trying to do. did i miss something? is there a better way?

ok, sorry, this isnt a bash script, but i would put it in one, sorry if my title is misleading
# 2  
Old 04-06-2011
Code:
rsync -az --delete /home/user/Videos/ /mnt/smbnet/share/Vids

# 3  
Old 04-06-2011
Sounds like you are trying to syncronise to directories, the best tool for this sort of thing is rsync not cp.

You probably need something like:
Code:
rsync -ar --dry-run --del --progress /home/user/Videos/ /mnt/smbnet/share/Vids

Once your happy with what is going to happen remove the --dry-run to do the actual sync.

---------- Post updated at 08:57 AM ---------- Previous update was at 08:51 AM ----------

@Nevyn, Don't think compression (-z) will help here as dest filesystem is mounted via samba (compress is maily for network performance when rsync is talking to a remote rsync server). Also I included the -r flag as original cp command was doing sub-directories.
# 4  
Old 04-06-2011
Yeah, I always put that z in there by habit. Good thinking with the --dry-run.

-a is the same as -rlptgoD so -r isn't needed.
This User Gave Thanks to Nevyn For This Post:
# 5  
Old 04-06-2011
Thanks Nevyn, I always added -r with -a (Lucky I never needed to copy all the files in a directory without sub dirs, or I would have found my misunderstanding at the expense of syncing a heap of files I didn't want to!)
# 6  
Old 04-06-2011
wow, thank you both for your input. i was going to look at rsync, but wasnt sure

couple of questions, explain how the -del or -delete works. is that the part that will remove a file from the dest if it has been removed from source? man rsync says -del and -delete are a bit different

if i have symlinks in certain directories that point to files that are being synced anyway do i still use the -l

---------- Post updated at 08:53 PM ---------- Previous update was at 08:32 PM ----------

think i answered my own questions

--ignore-existing will not sync the file if it exists on the dest, but will it check to see if the file has changed first before it skips it?
# 7  
Old 04-06-2011
The difference between -del and -delete is just when the delete is done, helps with files that are linked to, it really comes into play on busy destination systems where directories are being monitored and the like.

Do you have links pointing outside the Videos tree?
You might be best in using --copy-unsafe-links anyway just incase a link outside the tree is created in the future.

--ignore-existing does what the description says - if file exists on the dest it's ignored (It will not change the dest file even if the timestamp/size/content/permissions are different)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to copy subfolder and files to matching directory

The bash executes but returns no results and the set -xv showed while the $run variable in blue, was extracted correctly, the $match value in green, was not, rather both values in home/cmccabe/Desktop/f1 were extracted not just the matching. There will always be an exact match from the $run to... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Programming

Program or bash script to see total progress of copy

hi all, i want a program or to make a bash script to find out the total ETA/percent (would be nice aswell a progress bar) of a copy recursive command so lets say i do - cp -r /source_folder/ /destinatation_folder/ and when i run it i get no information on the screen of how the copy is... (20 Replies)
Discussion started by: robertkwild
20 Replies

3. Shell Programming and Scripting

Bash for checking and copy Daily files and send an email

Hello, Trying to get a bash for files received on daily basis and want to copy those files to different directory and send an email notification if file exists then send the file counts else Alert with no file received. FileName format: DailyTransaction_2015-03-09_ 200.csv before 200 their is... (1 Reply)
Discussion started by: krux_rap
1 Replies

4. Shell Programming and Scripting

Bash script to copy apache log files to client directory

Our Apache log files are written to a location on the server that we as clients have no access. Don't ask. Every month, I have to e-mail the administrator to have him manually copy our Apache log files to a directory in our file space. You can probably guess how efficient it is to do things this... (3 Replies)
Discussion started by: gregraven
3 Replies

5. Shell Programming and Scripting

Error on script to copy files

Hi I have the following script to copy files from one directory to another: #!/bin/sh touch -mt 201304240000 /var/tmp/ref1 touch -mt 201305152359 /var/tmp/ref2 find /moneta_collected02/in_psl -type f \( -newer /var/tmp/ref1 -a ! -newer /var/tmp/ref2 \) > file_lst cp -pr $(< file_lst)... (6 Replies)
Discussion started by: fretagi
6 Replies

6. Shell Programming and Scripting

Compare & Copy Directories : Bash Script Help

Beginner/Intermediate shell; comfortable in the command line. I have been looking for a solution to a backup problem. I need to compare Directory 1 to Directory 2 and copy all modified or new files/directories from Directory 1 to Directory 3. I need the directory and file structure to be... (4 Replies)
Discussion started by: Rod
4 Replies

7. Shell Programming and Scripting

Copy Files with script

Hello, I have written a script to copy files from one partion to another. Not sure if this is correct. #!/bin/sh CDR_SOURCE=/storage/archive/logmgmt/result/billing/ CDR_DEST=/storage4/archive/logmgmt/result/billing/ cp $CDR_SOURCE $CDR_DEST; exit 0 The CDR_SOURCE folder has... (5 Replies)
Discussion started by: Siddheshk
5 Replies

8. Shell Programming and Scripting

Bash script to copy timestamps of multiple files

Hi, I have a bunch of media files in a directory that have been converted (from MTS to MOV format), so my directory contains something like this: clip1.mts clip1.mov clip2.mts clip2.mov The problem is that the .mov files that have been created have the timestamps of the conversion task,... (2 Replies)
Discussion started by: Krakus
2 Replies

9. Shell Programming and Scripting

Help: Bash backup script (includes copy, test-

Basically it's for a work assignment. Have to make a menu with the following choices ***************menu********************* 1) Show Current Directory 2) Dispaly Current Time and Date 3) Copy 4) Change Password 5) write directory to file 6) Edit File Directory 7) Make backup from... (1 Reply)
Discussion started by: Covax
1 Replies

10. Shell Programming and Scripting

Simple BASH shell script to rename webcam jpg and copy into a new directory.

System: Ubuntu Intrepid Ibex I'm running webcamd as a sort of "security" program, but I need a script that will archive my webcam.jpg files. So, take the following file: /home/slag/www/webcam.jpg Rename it--preferably with a time stamp. Place it in say: /home/slag/www/history/ ... (4 Replies)
Discussion started by: robfindlay
4 Replies
Login or Register to Ask a Question