RSync + Pelican: A Short Note About Permissions

Yesterday I spent most of my time dabbling in Pelican’s configuration file. Right now how is set is pretty simple. I just rsync the data to the server, and back up the project on a weekly basis to my personal account in BitBucket. There’s a catch on this, any tool using rsync will upload the data as the user you are uploading it as. This doesn’t sound as a problem at all if you are using a shared hosting! However, I use a VPS from DigitalOcean, so it sort of changes quite a bit.

I’ll be frank, before explaining my solution which is just a simple line. I haven’t configured my nginx completely, and if there’s another way to do this it’s lost on me. Feel free to contact me, my e-mail is in the About Me page!

What I did was simple, edit your Pelican generated Makefile and add this line in the rsync_upload action:

rsync_upload: publish
rsync -e "ssh -p $(SSH_PORT)" -P -rvzc --delete $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) --cvs-exclude
ssh $(SSH_USER)@$(SSH_HOST) "chown -R www-data:www-data $(SSH_TARGET_DIR)"

That’s all you really need to solve the permission problems. There’s another way which is adding rsync to sudoers, but doing so introduces a security risk. The alteration made my way simply re-uses the variables that were previously declared. Once rsync finishes syncing the files, it will make open up ssh and chown the folder.

That’s all, and if you are using vim. Type :make rsync_upload (you must have your virtualenv enabled if you didn’t install it system wide). 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.