Skip to content

Instantly share code, notes, and snippets.

@lene
Last active September 8, 2022 22:05
Show Gist options
  • Save lene/9409dcb7a07276533d51bab734e6c260 to your computer and use it in GitHub Desktop.
Save lene/9409dcb7a07276533d51bab734e6c260 to your computer and use it in GitHub Desktop.
Sync Music dir to Google Drive
sudo apt install google-drive-ocamlfuse # to mount google drive as a pseudo fs
sudo apt install athena-jot # for generating the list of {A..Z} in fish shell on the fly
sudo apt install parallel # to control running jobs in parallel
# set up google drive, see https://github.com/astrada/google-drive-ocamlfuse/wiki/Authorization
google-drive-ocamlfuse
# mount google drive
set DRIVE_DIR GoogleDrive
google-drive-ocamlfuse ~/$DRIVE_DIR/
set DIRS va spoken mix tape (jot -c 26 a z) \#
# using GNU parallel can limit the number of rsync jobs run in parallel
set NUM_JOBS 5
parallel --jobs $NUM_JOBS --tag --linebuffer \
rsync -trluhvW --progress --delete --inplace --stats ~/"Music/{}/" ~/"$DRIVE_DIR/Music/{}" ::: $DIRS
# alternatively: start all jobs in background at once instead of using GNU parallel
for i in $DIRS
echo $i
# the --inplace option is key so that already present files are not synced
# see https://github.com/astrada/google-drive-ocamlfuse/wiki/rsync
rsync -trluhvW --progress --delete --inplace --stats ~/"Music/$i/" ~/"$DRIVE_DIR/Music/$i" &
sleep 60 # optional to not spam too much output at once
end
@lene
Copy link
Author

lene commented Sep 7, 2022

  • running multiple jobs in parallel speeds up rsync performance:
    • while rsync is scanning instead of transferring
    • when single rsync processes get temporarily stuck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment