How to back up your Drupal's files directory
Mon, 2009/03/09 - 16:29 — balu
Recently I wanted to make sure that all images and other files from our server are downloaded to our development environment. This is a short note on how to do this effectively.
Naturally re-downloading all of the files is long, a waste of bandwidth and so on, so I decided to use rsync, a smart tool that can actually look for changed, or new files and only download those. In addition, it is smart enough to learn about files to exclude, which is really useful when someone is using imagecache for instance. Imagecache stores all its processed, cached images under the imagecache folder by default, so we can use this condition as exclusion pattern.
Lets write a small shell-script for clarity and our sane minds:
#!/bin/sh
# user who can access the files on our server
USER='drupaluser'
# server url, or ip
SERVER='example.com'
# absolute path to the files folder, trailing slash is important
FILES='/path/to/drupal/files/'
# exclusion pattern
EXCLUDES='imagecache'
LOCAL_FILES='/path/to/backup/files'
rsync -azW --exclude=$EXCLUDES $USER@$SERVER:$FILES $LOCAL_FILES
some notes:
the -a flag makes sure that the sync is recursive, permissions are stored, links are links etc. -z enables compression and -W forces the program to focus on whole files only. If one wants to run multiple tests, a -v flag for verbose might be useful. rsync can also accept a list of excluded folders, in that case write them into a file, and use the flag —exclude-file=<path-to-excludefile>.
Comments
Fri, 2009/04/10 - 12:24 — Drupal Development (not verified)
I came across this site and
I came across this site and it was extremely helpful!
Thu, 2009/08/13 - 06:08 — Webzen Sam (not verified)
Thanks for the handy script.
Thanks for the handy script. A few notes:
My version of rsync uses —exclude-from instead of —exclude-file.
Also you missed the ‘r’ from rsync in the final line of the script.
Sat, 2009/08/29 - 15:47 — balu
thanks, fixed. Also, you can
thanks, fixed. Also, you can add more directories to exclude by adding —exclude multiple times.