I have a working capistrano task that uses rsync to sync the uploads folder from development to staging or production and figured I’d share it here. Note that this task performs a bi-directional sync.
# Swiped from Mixd
# https://github.com/Mixd/wp-deploy
# Modified directory structure
# added option for non-standard SSH port
namespace :uploads do
desc "Syncs uploads directory from local to remote"
task :sync do
run_locally do
roles(:all).each do |role|
execute :rsync, "-avzO -e \'ssh -p 4147\' #{role.user}@#{role.hostname}:#{shared_path}/web/app/uploads web/app/uploads"
execute :rsync, "-avzO -e \'ssh -p 4147\' web/app/uploads/ #{role.user}@#{role.hostname}:#{shared_path}/web/app/uploads"
end
end
end
end
You’ll notice I’m using a non-standard port (4147) as its a good security practice to close the default SSH port (22).
To use this just create the directory structure:
lib/capistrano/tasks/content.cap
Then execute:
bundle exec cap production uploads:sync
You can view the Mixd docs on Github for more information.