Created
January 16, 2023 07:21
-
-
Save Hakier/a585de0fd9bc223febab4ec64517568b to your computer and use it in GitHub Desktop.
Rsync: backup only specified files and preserve relative paths without a parent directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#setup | |
mkdir -p playground/{source,target} && cd playground | |
mkdir -p source/{a,b,c}/{d,e,f}/{g,h,i} | |
touch source/{.,a,b/{e,f},c/d/{g,h,i}}/{1,2,3,4,5} | |
#first sync | |
cd source && rsync -aR 3 a/ b/f/ c/d ../target/ --delete && cd - | |
find -type f | |
#remove a file | |
echo -n 'Remove a file (source/b/f/3) to check if --delete will work as expected [enter]: '; read cnt | |
rm source/b/f/3 | |
#second sync | |
cd source && rsync -aR 3 a/ b/f/ c/d ../target/ --delete && cd - | |
find -type f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment