Drush + Bash + Cron: Datbase Backup Goals
- Scan sites directory for a given drupal install
- Find all multisite folders/symlinks
- For each multisite:
- Use Drush to clear cache - we dont want cache table bloating up the MySQL dump file
- Use Drush to delete watchdog logs - we dont want watchdog table bloating up the MySQL dump file
- Use Drush to backup the database to pre-assigned folder
- Use tar to compress and timestamp the Drush generated sql file
- Setup Crontab to run perodically with the above commands as a bash file
Assumptions and Instructions
You will need to adjust the Bash file if any of these are not the same on your server
- Drupal is installed in /var/www/html/drupal
- Multisites are setup in the /var/www/html/drupal/sites folder
- Backup folder exists in /var/www/backup/sqldumps
- Drush is already installed in /root/drush/drush. If drush is not installed follow this Drush installation guide
- AWK is already installed, if not, type: sudo yum install gawk
Drush Backup BASH file
Copy paste the code below and create a new bash file ideally in your/root home folder. Make the Bash file executable.
#!/bin/bash # # Adjust to match your system settings DRUSH=/root/drush/drush ECHO=/bin/echo FIND=/usr/bin/find AWK=/bin/awk # Adjust to match your system settings docroot=/var/www/html/drupal backup_dir=/var/www/backup/sqldumps multisites=$1 START_TIME=$(date +%Y%m%d%H%M); # Add all multisites for a given docroot into a list. Detects all web addresses which are a directory which isn't named all, default or ends in .local. if [ "${multisites}" = "all" ];then # If multisites are folders change -type d # If multisites are symlinks change -type l # Adjust $8 to match your docroot, it $x needs to be the name of the multisite folder/symlink multisites_list="`$FIND ${docroot}/sites/* -type l -prune | $AWK -F \/ '$8!="all" && $8!="default" && $8!~/\.local$/ { print $8 }'`" else multisites_list=$multisites fi # Must be in the docroot directory before proceeding. cd $docroot for multisite in $multisites_list do # Echo to the screen the current task. $ECHO $ECHO "##############################################################" $ECHO "Backing up ${multisite}" $ECHO $ECHO # Clear Drupal cache $DRUSH -y -u 1 -l "${multisite}" cc all # Truncate Watchdog $DRUSH -y -u 1 -l "${multisite}" wd-del all # SQL Dump DB $DRUSH -u 1 -l "${multisite}" sql-dump --result-file="${backup_dir}"/"${multisite}".sql # Compress the SQL Dump tar -czv -f "${backup_dir}"/"${START_TIME}"-"${multisite}".tar.gz -C "${backup_dir}"/ "${multisite}".sql # Delete original SQL Dump rm -f "${backup_dir}"/"${multisite}".sql $ECHO $ECHO $ECHO "Finished backing up ${multisite}" $ECHO $ECHO "##############################################################" done
Setup Crontab
Assuming your bash file containing the code above is saved as /root/drush_backup.sh, you can setup a crontab for root user.
crontab -e 1 1 * * * /root/drush_backup_db.sh
相关推荐
3. **Using Drupal**: 强烈推荐的这本书旨在教你如何有效地使用Drupal构建网站,无论你是新手还是有经验的用户。它将介绍最佳实践,帮助你规划项目、选择合适的模块、优化工作流,并提供实际案例研究。书中可能会...
Write a Drupal 8 module with custom functionality and hook into various extension points Master numerous Drupal 8 sub-systems and APIs Model, store, and manipulate data in various ways and for various...
通过以上分析可以看出,“using Drupal 中文翻译版”这份文档旨在帮助中文用户更好地理解和使用Drupal系统。虽然还有两个章节未完成翻译,但通过细致的准备工作和严谨的翻译流程,相信很快就能完善这一缺陷。对于想...
Drupal employs a specialized templating system and supports themes, which allow you to change the look and feel of the system's front and back-end interfaces. Drupal 6 Themes is an ideal introduction...
Several projects point to a decoupled future for Drupal, including the Contenta CMS and work to modernize Drupal’s JavaScript using React. Begin learning about these and other exciting developments ...
The book also covers some more advanced topics that beginners often ask about, such as getting set up with Git and using source control, using MySQL to interact with a database, and a guide to ...
Using Drupal 8 Explained, you can master Drupal 8 by using step-by-step examples. Drupal 8 is an amazingly powerful system, but many newcomers can find it confusing. We wrote this book to make Drupal ...
【标题】:“dstack-drupal:集成Drush的Drupal配置原型,用于测试dStack与Drupal的接口” 在本文中,我们将深入探讨“dstack-drupal”项目,这是一个专为验证dStack与Drupal集成点而设计的原型配置。该配置特别...
Drupal 8是Drupal的一个主要版本,它在2016年3月发布。《Drupal 8 Development Cookbook》一书提供了一系列的解决方案,帮助开发者熟悉Drupal 8的诸多功能,并教会他们如何使用这些功能来创建内容丰富的网站。 由于...
"Using Drupal"这本书是Drupal学习者和开发者的重要资源,它深入介绍了如何有效地使用这个平台。这里,我们将深入探讨Drupal的核心概念、源代码管理和PHP编程在Drupal中的应用。 1. Drupal核心概念: - **模块化...