rsync delete single file from the target folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting rsync delete single file from the target folder
# 1  
Old 11-21-2011
rsync delete single file from the target folder

Hi

We want to delete a single file from the destiantion directory using rsync. Is it possible to do this ? or Do we have any alternate approaches in rsync( for ex applying some filters ..etc)

For ex:
-----------------------------------------------
Source (Folder)
a.txt
b.txt

Dest(Folder)
a.txt
b.txt
c.txt
d.txt
------------------------------------------------
We want to delete only "c.txt" file from the destination not "d.txt".
Please share your thoughts.
# 2  
Old 11-21-2011
afaik that's not possible, sure you could filter d.txt, but then it wont be transferred too


maybe you could exclude all --exclude='*' and include your file --include=c.txt, use rsync with --delete, and specify a "/" at the end of the folders, but use --dry-run to test
# 3  
Old 11-21-2011
This may accomplish what you're trying to do, or at least point you in the right direction:

Code:
rsync -avz --exclude="d.txt" --delete --delete-during --progress --stats /dir1 /dir2

sending incremental file list
./
deleting c.txt

Number of files: 4
Number of files transferred: 0
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 76
File list generation time: 0.002 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 88
Total bytes received: 15

sent 88 bytes  received 15 bytes  206.00 bytes/sec
total size is 0  speedup is 0.00

Hope this helps.
# 4  
Old 11-21-2011
Thanks for your response. In this scenario its working fine.

But here we need to know the list of exclude files before. And also i noticed that it is not only performing deletion, if there are any updates/add in the source.. it is trying sync those files as well.

Is there any way to restrict the updates/add files? And also is there any option to exlucde all files except particular file for deletion?

I tried with the below option but it didn't work
Code:
rsync -avz --exclude="*" --include="c.txt" --delete --delete-during --progress --stats  /source/  /dest/

Please share your ideas....
Thanks you..

---------- Post updated at 05:56 PM ---------- Previous update was at 10:46 AM ----------

--include and --exclude options order makes difference.

I tried with below order
Code:
rsync -avz  --include="c.txt" --exclude="*"  --delete --delete-during --progress --stats /source/ /dest/

It works and the operation is only on the specified files.

I have one more question.. how can we achieve the same functionality for multiple files with different source and destination using single rsync command?(instead of running rsync multiple times).

Thanks !

Last edited by vbe; 12-08-2011 at 11:16 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

2. UNIX for Advanced & Expert Users

Rsync with --delete but do not delete peer dirs on target

rsync with --delete won't honor the delete if the source is something/*. I want the delete to work, but not to delete directories on the target that are peer to the intended directory. For example, using these source and target file structures: Source on desktop: ~/ Money/ ... (4 Replies)
Discussion started by: JavaMeister
4 Replies

3. Shell Programming and Scripting

Rsync in bash script doesn't work even after placing pub key in target server

Hello Friends, My bash script is like this #!/bin/bash # request Bourne shell as shell for job #$ -S /bin/bash # assume current working directory as paths #$ -cwd #$ -N rsync-copy # # print date and time date rsync -rltD --progress "ssh -i /home/myname/.ssh/id_rsa"... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

4. Shell Programming and Scripting

Shell script which will check the target file and folder exists and copy it

Hi All, I am a beginner in this and trying to write a shell script in linux which will : 1. Ask for a file name and check if its exists. 2. If file exists only then it will ask for the new target folder, after entering target folder name it will check if it exists. 3. If target folder... (3 Replies)
Discussion started by: ashish_neekhra
3 Replies

5. UNIX for Dummies Questions & Answers

Rsync whole folder and head of each file

Hello, I am trying to backup the whole folder which contains years of data and huge size, some files are > 10GB. I want keep the exact organization of the folder, except that for bigger file only part of it (say head -50, or simply only the name of the file) will be kept. Then the structure of the... (2 Replies)
Discussion started by: yifangt
2 Replies

6. Shell Programming and Scripting

How to delete more than 7 days file from Target folder?

Hi Team, I have to remove files which are more than 7 days in my target directory. I have this script but using this i faced some problems like, removed library files of unix. for abc in `find /xxx/abc/OutputFiles/xxxx_*.txt -type f -mtime +5|xargs ls 1` do echo "xxx files are:"$abc ... (1 Reply)
Discussion started by: harris
1 Replies

7. Shell Programming and Scripting

rsync delete specific files - from different target folder

Hi, I need to use rsync to delete multiple files(only specified files not all) using --delete option, these files are located in different target folders. Instead of running rsync command multiple times for each file, can we achieve this with one time execution? your help is much... (0 Replies)
Discussion started by: MVEERA
0 Replies

8. Shell Programming and Scripting

rsync a single file

I have been using rsync scripts for a while and use them to sync directories across my servers. However i need to set up an rsync script to copy only one file from a server. Is this possible with rsync? If so how would i do this? I have looked on examples on the internet and only see examples for... (2 Replies)
Discussion started by: timgolding
2 Replies

9. Shell Programming and Scripting

Rsync help - unable to delete the Source file

Hi All, I am facing problem deleting Source while using the rsync command. rsync --include=*`date --date="-1 day" \+\%Y\%m\%d`* --include=*`date +\%Y\%m\%d`* --exclude=* --delete-after -auvb -e ssh USER@SERVER:SOURCE DESTINATION However the sync happens but not the deletion of the source... (1 Reply)
Discussion started by: amitkhiare
1 Replies

10. Shell Programming and Scripting

File Management: How do I move all JPGS in a folder structure to a single folder?

This is the file structure: DESKTOP/Root of Photo Folders/Folder1qweqwasdfsd/*jpg DESKTOP/Root of Photo Folders/Folder2asdasdasd/*jpg DESKTOP/Root of Photo Folders/Folder3asdadfhgasdf/*jpg DESKTOP/Root of Photo Folders/Folder4qwetwdfsdfg/*jpg DESKTOP/Root of Photo... (4 Replies)
Discussion started by: guptaxpn
4 Replies
Login or Register to Ask a Question