I am running the command:
rsync -ab --delete-delay /media/blueray/WDRed /media/blueray/UltrastarDaily Just to be clear, it delete destination file (--delete-delay) if the file is removed from the source.
And it is yielding the following output (part of the output):
rsync: open "/media/blueray/UltrastarDaily/WDRed/_Working/_NotesFiltered/.git/objects/aa/0f7214d22e712099a0d3509c72308146893e57" failed: Permission denied (13)
rsync: open "/media/blueray/UltrastarDaily/WDRed/_Working/_NotesFiltered/.git/objects/ab/b150515f74a76f331ee275ef2768a91115b320" failed: Permission denied (13)
rsync: open "/media/blueray/UltrastarDaily/WDRed/_Working/_NotesFiltered/.git/objects/ab/baad7a7409b4d0bbdcef7c9890bb1f5d46a823" failed: Permission denied (13)
rsync: open "/media/blueray/UltrastarDaily/WDRed/_Working/_NotesFiltered/.git/objects/b3/8ed79ad4f5956cfa129fe1df0e9ec00c746672" failed: Permission denied (13)
rsync: open "/media/blueray/UltrastarDaily/WDRed/_Working/_NotesFiltered/.git/objects/b5/8f91ac5efdc0e53a83eba11a0e632a4dea73ec" failed: Permission denied (13)
rsync: open "/media/blueray/UltrastarDaily/WDRed/_Working/_NotesFiltered/.git/objects/b5/abcc64e88d77813bdc47005f9accb72746326a" failed: Permission denied (13)
rsync: open "/media/blueray/UltrastarDaily/WDRed/_Working/_NotesFiltered/.git/objects/b5/f6af97229a1bd644fc58a9c54c136f880fa530" failed: Permission denied (13)
rsync: open "/media/blueray/UltrastarDaily/WDRed/_Working/_NotesFiltered/.git/objects/b6/400def87b4544f9ef2b246be8170e5b03a686c" failed: Permission denied (13)I checked the file permission. It is showing:
% ls -lg
.r--r--r-- 128 blueray blueray 7 Feb 4:36 0f7214d22e712099a0d3509c72308146893e57
.r--r--r-- 100 blueray blueray 18 Dec 2020 4c43240f470ae0d19198beab1ceee59b8ba400
.r--r--r-- 236 blueray blueray 18 Dec 2020 9b80263fab88c02738a91bbe15763801b415fd
.r--r--r-- 626 blueray blueray 18 Dec 2020 47ffc8062e197dc9c76f199032a2fe5f0c40a8
.r--r--r-- 1.1M blueray blueray 5 Apr 23:13 217fc19b7887fe3ba24f828aa2880235e16158
.r--r--r-- 2.4k blueray blueray 22 May 23:47 677b3290ebd20ff33b0496f76e1e71e6566e07
.r--r--r-- 25k blueray blueray 18 Dec 2020 7682be228dd8c0e303d9bb51c2388ab122afe3
.r--r--r-- 350 blueray blueray 7 Feb 4:36 a33ca86640f0614b80bbb27bdcf7941c5c04f9
.r--r--r-- 122k blueray blueray 22 May 23:47 a70c7a10521b3c0e320385f1528e8975bb1b16
.r--r--r-- 209 blueray blueray 18 Dec 2020 a86944d79a34ef90d3d9f4db20a9622a920695
.r--r--r-- 1.2k blueray blueray 18 Dec 2020 b93b3e139d6362c6120193a49ee635ceeeba85
.r--r--r-- 1.3k blueray blueray 18 Dec 2020 c9b598d13d373fe0d789d9f6211e9bbb244a8e
.r--r--r-- 385 blueray blueray 18 Dec 2020 cdda3fa1a3f0bbfda08072c20eba28bec1dcf8
.r--r--r-- 137 blueray blueray 18 Dec 2020 d11be88a036d4b42fb9826db1f74b2ff818577
.r--r--r-- 1.1M blueray blueray 18 Dec 2020 fae0391be02b5054ad949e684ebe8bcb151ac0If I give write permission to these git objects then the rsync command works.
My problem is, I have many git repos in backup directory. I can not go to each directory and change permission after every commit.
If I could give write permission to rsync files for git objects then it would be better. Actually any workaround that does not involve going to each directory and change permission after every commit will be better.
1 Answer
You would be ok with a script that first changes the permissions.
It could work on specific directories or on all .git/objects in a (sub)set of directories.
Taking as an example the command line you posted in the question
rsync -ab --delete-delay /media/blueray/WDRed /media/blueray/UltrastarDaily and naming rsync_my.sh script below,
#!/bin/bash
TARGET="${@:$#}" # last parameter
SOURCE="${@:(-2):1}" # second to last parameter
TARGET2="${TARGET}/$(basename ${SOURCE})/_Working/_NotesFiltered/
for d in $(find ${TARGET2} -type d -name .git) ; do chmod -R +w $d/objects for d2 in $(find ${d} -type d) ; do chmod +x $d2 done
done
rsync "$@"you would execute
$ chmod +x rsync_my.sh
$ ./rsync_my.sh -ab --delete-delay /media/blueray/WDRed /media/blueray/UltrastarDaily The first command is needed only once. SOURCE would be /media/blueray/WDRed and TARGET would be /media/blueray/UltrastarDaily.
Please test it and post feedback.
To test, you could
- Put together a dummy directory/file structure with some 10 files that replicates the essential structure of your target dir, and execute the script.
- With
rsync, use option--dry-runto only see what would be done, and create a log file that you can later inspect with--log-file=mylog.log.
Parameter expansion/extraction may need fine tuning.
Related:
5