Hi all,
I found that upgrading the Drupal core module can be really time consuming if you have a lot of installed modules, so I wrote a few scripts for Linux (sorry, not sure which distribution) to automate the process. I'm posting here in case they might be useful to others. Please post back if you find this helpful.
An overview follows:
web_backup - allows you to specify a directory under your home directory to create a backup. The script double checks to see that the .htaccess file is copied and also compares all the files in each directory. You would want to be sure to backup your database separately.
web_restore - allows you specify a backup directory to copy files into the web directory. You will need to edit this script to specify the web directory. Like the web_backup script, this will compare .htaccess and files to confirm a successful restore.
drupal_upgrade - after you've run the web_backup command, you can run this script to extract the new Drupal tar file then use it to rebuild your Drupal site in the web directory. The script first checks that you have a good backup, then deletes the current site, then creates the core files, and finally copies .htaccess and the sites, files, and modules directories from backup, making sure not to overwrite newer core files. You can use the web_resotre command to copy the site back if anything goes wrong.
See below for full code.
web_backup:
# Use this script to create a backup of web directory
# Make sure to backup your database separately!
# Configure top level directory and user account and web directory below:
topdir=$HOME
webdir=$HOME/public_html
#
# Main program follows:
echo " - - - W E B D I R E C T O R Y B A C K U P - - -"
echo ""
echo "Configuration (edit this script to change):"
echo " Top directory = $topdir"
echo " Web directory = $webdir"
echo ""
echo "Please hit enter to confirm the above configuration or type Ctrl-C to exit"
read enterkey
echo "Enter name of directory for new backup (e.g. public_html_copy):"
read relbackupdir
if test $relbackupdir
then
backupdir=$topdir/$relbackupdir
if mkdir $backupdir
then
echo "Created $backupdir"
echo "Copying files..."
cp -rfdp $webdir/* $backupdir
cp -p $webdir/.htaccess $backupdir/.htaccess
cp -fp $webdir/sites/default/* $backupdir/sites/default/
echo "Confirming copy of .htaccess file..."
ls $backupdir/.htaccess -al
echo "Confirming backup files..."
echo ""
cd $backupdir
ls -R > $topdir/web_compare_backup.txt
cd $webdir
ls -R > $topdir/web_compare_current.txt
diff $topdir/web_compare_backup.txt $topdir/web_compare_current.txt > $topdir/web_compare.txt
if test -s /home/afu/compare.txt
then
echo "Backup directory contents do not match current web directory contents. Backup failed."
echo "Please review file $topdir/web_compare.txt to view differences."
echo ""
exit 1
else
rm $topdir/web_compar*.txt
echo "Backup complete."
fi
else
echo ""
echo "Could not create $backupdir. Backup canceled."
fi
else
echo "No directory provided. Backup canceled."
fi
echo ""
web_restore:
# Use this script to restore a copy of the web directory
# Configure top level directory and user account and web directory below:
topdir=$HOME
webdir=$HOME/public_html
#
# Main program follows:
echo " - - - W E B D I R E C T O R Y R E S T O R E - - -"
echo ""
echo "Configuration (edit this script to change):"
echo " Top directory = $topdir"
echo " Web directory = $webdir"
echo ""
echo "Please hit enter to confirm the above configuration or type Ctrl-C to exit"
read enterkey
cd $webdir
ls > $topdir/web_rest_contents.txt
if test -s $topdir/web_rest_contents.txt
then
echo "Web directory is not empty. Restore canceled."
echo "Please backup web site with web_backup command, delete web site, and try again."
echo ""
rm $topdir/web_rest_contents.txt
exit 1
else
rm $topdir/web_rest_contents.txt
fi
cd $topdir
ls -l | grep ^d
echo "Enter the name of the web backup directory from those above:"
read relbackupdir
if test $relbackupdir
then
backupdir=$topdir/$relbackupdir
echo "Copying files..."
cp -rfdp $backupdir/* $webdir
cp -p $backupdir/.htaccess $webdir/.htaccess
cp -fp $backupdir/sites/default/* $webdir/sites/default/
echo "Confirming copy of .htaccess file..."
ls $webdir/.htaccess -al
echo "Confirming restore of backup files..."
echo ""
cd $backupdir
ls -R > $topdir/web_rest_backup.txt
cd $webdir
ls -R > $topdir/web_rest_new.txt
diff $topdir/web_rest_backup.txt $topdir/web_rest_new.txt > $topdir/web_rest_compare.txt
if test -s /home/afu/web_rest_compare.txt
then
echo "New web directory contents do not match backup directory contents. Restore failed."
echo "Please review file $topdir/web_rest_compare.txt to view differences."
echo ""
exit 1
else
rm $topdir/web_rest_*.txt
echo "Restore complete."
fi
else
echo "No backup directory provided. Restore canceled."
fi
echo ""
drupal_upgrade:
# Configure top directory and user account and web directory below:
topdir=$HOME
webdir=$HOME/public_html
#
# Main program follows:
echo " - - - D R U P A L U P G R A D E - - -"
echo ""
echo "Please backup the contents of the web directory before running this script."
echo ""
echo "Configuration (edit this script to change):"
echo " Top directory = $topdir"
echo " Web directory = $webdir"
echo ""
echo "Please hit enter to confirm the above configuration or type Ctrl-C to exit"
read enterkey
echo ""
cd $topdir
ls -l | grep ^d
echo "Enter the name of the web backup directory from those above:"
read relbackupdir
if test $relbackupdir
then
backupdir=$topdir/$relbackupdir
cd $backupdir
ls -R > $topdir/drp_up_compare_backup.txt
cd $webdir
ls -R > $topdir/drp_up_compare_current.txt
diff $topdir/drp_up_compare_backup.txt $topdir/drp_up_compare_current.txt > $topdir/drp_up_compare.txt
if test -s /home/afu/compare.txt
then
echo ""
echo "Backup directory contents do not match current web directory contents. Upgrade canceled."
echo "Please backup web site with web_backup command and try again."
echo ""
exit 1
fi
else
echo "No backup directory provided. Upgrade canceled."
exit 1
fi
rm $topdir/drp_up_compar*.txt
echo ""
echo ""
echo "Candidate Drupal files follow:"
cd $topdir
ls dru*.ta*
echo ""
echo "Please enter the name of new Drupal version tar file or type Ctrl-C to exit:"
read drupalfile
if test $drupalfile
then
echo ""
echo "Extracting Drupal files..."
if tar -xzpf ./$drupalfile
then
echo "Extract complete. Directories follow:"
cd $topdir
ls -l | grep ^d
echo ""
echo "Enter name of new Drupal directory:"
read drupaldir
if test $drupaldir
then
echo ""
echo "Please hit enter to delete web site and upgrade or type Ctrl-C to exit"
read enterkey
cd $webdir
# delete site
if rm -rfd *
then
echo "Deleted web site..."
else
echo ""
echo "Could not delete current web site. Upgrade canceled."
echo ""
exit 1
fi
# copy new Drupal version and copy .htaccess file from backup
if cp -rfdp $topdir/$drupaldir/* $webdir/
then
echo "Copied new Drupal files to web site..."
else
echo ""
echo "Error on copy of new Drupal files to web site. Upgrade canceled."
echo "Please execute web_restore command."
echo ""
exit 1
fi
mv $webdir/.htaccess $webdir/.htaccess_original
if cp -p $backupdir/.htaccess $webdir/
then
echo "Copied new .htaccess file from backup..."
else
echo "Error on copy of .htaccess from backup. Please review or execute web_restore command."
fi
# copy sites directory from backup
mv $webdir/sites/default/settings.php $webdir/sites/default/settings_original.php
if cp -rfdp $backupdir/sites $webdir/
then
echo "Copied sites directory from backup to web site..."
else
echo ""
echo "Error on copy of backup sites directory to web site. Upgrade canceled."
echo "Please execute web_restore command."
echo ""
exit 1
fi
# copy files directory from backup
if cp -rfdp $backupdir/files $webdir/
then
echo "Copied files directory from backup to web site..."
else
echo ""
echo "Error on copy of backup files directory to web site. Upgrade canceled."
echo "Please execute web_restore command."
echo ""
exit 1
fi
# copy modules directory from backup (only if files are missing or newer)
if cp -rfdpu $backupdir/modules $webdir/
then
echo "Copied modules directory from backup to web site... (if new or missing)"
else
echo ""
echo "Error on copy of backup modules directory to web site. Upgrade canceled."
echo "Please execute web_restore command."
echo ""
exit 1
fi
echo ""
echo "Upgrade complete. Please run update.php"
else
echo "No Drupal directory provided. Upgrade canceled."
fi
else
echo "Could not extract Drupal files. Upgrade canceled."
fi
else
echo "No Drupal file provided. Upgrade canceled."
fi
echo ""