How do i delete a file in remote location - rsync

I have delete 1 file locally and added new files locally, i dont want to sync those new files to the remote system but rather delete only the one that has been removed from src.I tried the command below but it deletes file from remote also.
rsync -avh --delete /home/ssastry/ ssastry#10.196.105.121:/tmp
I want the only file deleted from local to get deleted from remote . i dont want new additions.

Try below command.
rsync -r --delete --existing --ignore-existing /home/ssastry/ ssastry#10.196.105.121:/tmp
From man page:
--existing :skip creating new files on receiver
--ignore-existing : skip updating files that exist on receiver

Related

deploy project to remote server with rsync command

I'm using rsync command to deploy symfony 4 project to remote server, every time when I make new change the command deploy all the project's file instead of new files !! which option to add to tell rsync that should only transfer new changes!
I'm using rsync like that :
rsync -av LocalProjectPath RemotePerverPath --include=public/.htaccess --include=public/build --include=vendor --exclude=".*"
I can refer you to this page for detailed information:
https://www.tecmint.com/sync-new-changed-modified-files-rsync-linux/
rsync has built-in parameters for those purposes
"--ignore-existing" allows you to transfer only new files.
"--update --dry-run" allows you to transfer only updated and modified files.

Copy and delete files from SFTP folder

I have to pick (remove) the files with file mask FileName_A_* and FileName_B_* from SFTP location and place them in an sharedrive.
I tried using WinSCP. I have created an HourlyFile.txt file with below code and placed it under C:\Program Files (x86)\WinSCP . Another batch file HourlyFile.bat to execute the script from HourlyFile.txt
HourlyFile.txt:
option batch abort
option confirm off
open sftp..........
get -filemask="FileName_A_*" /outbound/test/* \\sharedrive
get -filemask="FileName_B_*" /outbound/test/* \\sharedrive
del /outbound/test/FileName_A_*
del /outbound/test/FileName_B_*
exit
HourlyFile.bat:
winscp.com /script=HourlyFile.txt
pause
I tried with below options to delete the file but got the error message "Unknown command". Also the above code is copying subfolder from /outbound/test/ , which it should not.
Commands tried:
del /outbound/test/FileName_A_*
-del /outbound/test/FileName_A_*
delete /outbound/test/FileName_A_*
delete /outbound/test/FileName_A_20190604_090002
delete /outbound/test/FileName_A_20190604_090002.csv
If you want to download and delete the files, you better use -delete switch of the get command. This way, you can be sure that WinSCP deletes only those files that were really successfully downloaded.
get -delete /outbound/test/FileName_A_* \\sharedrive\
get -delete /outbound/test/FileName_B_* \\sharedrive\
See WinSCP article How do I create script that synchronizes files and deletes synchronized files from source afterward?
To answer your literal question: WinSCP has no del command. WinSCP has rm command:
rm /outbound/test/FileName_A_*
rm /outbound/test/FileName_B_*
On some Unix servers the wildcard command would be:
mrm /outbound/test/FileName_A_*
, in the event
rm /outbound/test/FileName_A_*
doesn't work, returning error:
rm: Access failed: File not found (/outbound/test/FileName_A_*)

rsync not copying my file from remote server

I have two VM's : dev and prod.
I want to use rsync to copy dump file from prod and then restore it on dev. I'm using this command to copy:
rsync -rave user#ip:/home/user/dumps /home/anotheruser/workspace/someapp/dumps
The same thing successfully copies static files (.html, .css) from another directory, but in this case only the folder itself is created but without the file:
/home/anotheruser/workspace/someapp/dumps
but I'm expecting:
/home/anotheruser/workspace/someapp/dumps/dumpfile
What is going wrong? dumpfile exists there user#ip:/home/user/dumps/dumpfile.
The command you want is probably this:
rsync -av user#ip:/home/user/dumps/ /home/anotheruser/workspace/someapp/dumps/
I've
removed the r because it's implied by the a anyway.
removed the e because that was probably your problem; it requires a parameter that you haven't given.
added the / at the end of the pathnames to make sure they're treated as directories.

Rsync wont delete files from an external drive

Can someone please tell me why the following command does not delete the extra files on backup2Drive.
Backup1Folder is a folder and backup2Drive is a drive.
rsync -avh --exclude '._*' --delete /Volumes/ext/Backup1Folder/ /Volumes/backup2Drive
you are either missing --delete-excluded or you are skipping the delete step because of previous i/o errors

Delete over rsync using ssh is not working

I'm doing an rsync trial where I have two files in the current folder:
share_2014_09_08.tar.gz share_2014_10_08.tar.gz
I want to rsync to a remote folder that contains three older files. I use the command:
rsync -avz --del ./*.tar.gz backups#pc01:/home/backups/monthly/
And the result int the destination folder is:
share_2014_03_05.tar.gz share_2014_09_08.tar.gz share_2014_10_08.tar.gz
As I understand it, this file:
share_2014_03_05.tar.gz
should have been deleted, so my question is what am I doing wrong.
You're passing to rsync a list of files that you want to synchronize. Not existing files are not passed, so delete option has no effects.
If you want to delete files, you'll have to synchronize the parent directory that contained removed files. You can use a include mask to only sync tarballs:
rsync -avz --include "*.tar.gz" --exclude "*" --del . backups#pc01:/home/backups/monthly/

Resources