Wednesday, April 24, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 9536  / 3 Years ago, wed, september 8, 2021, 10:44:15

I have a script that uses scp to backup some files of my PC into another PC connected in LAN, something like that:



#!/bin/bash
scp some_directories host@ip-address:backupFolder/


I use a public Key so it works without insert any password, I have just to execute it.



The problem is that if I backup some file from my PC and then I remove it (from my PC not from the remote one), when I execute this script again it copy the new files and overwrites the existing ones but does not remove the previous backuped files that are no longer present in my PC.



So I need a way to remove files in the remote PC via some script. The only way I know is to login in with ssh host@ip and then to use rm but clearly I can't write a script like this:



#!/bin/bash
ssh host@ip-address
rm -r backupFolder/


because in this way the rm command look for the backupFolder in my PC and not in the remote one.


More From » ssh

 Answers
7

You description is a bit vague. BUt I reckon what you want to archive is to sync the remote backup folder with your PC (sync directories).



In this case, the most suitable tool would be rsync instead of scp.



Good news is that rsync works perfectly fine over SSH, your public key authentication will keep working like a charm.



You can use command like below to keep your backup on the remote server in sync with your PC



rsync -avz --delete --progress --stats some_directories host@ip-address:backupFolder/




NOTE: be careful with rsync's trailing slash => /. Read the man pages.



[#30868] Thursday, September 9, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
istmasted

Total Points: 287
Total Questions: 130
Total Answers: 153

Location: Burkina Faso
Member since Thu, Dec 23, 2021
2 Years ago
;