Paste Description for drupal-db-maint.sh
From: http://michael.susens-schurter.com/blog/2007/08/03/drupal-database-maintenance-script/
- drupal-db-maint.sh
- Friday, August 3rd, 2007 at 10:22:38am MDT
- #!/bin/sh
- echo `date` - Starting Drupal database maintenance
- MYSQL_USERNAME='insert your MySQL username here'
- MYSQL_PASSWORD='insert your MySQL password here'
- MYSQL_DATABASE='insert your database name here'
- # Note: 2592000 = sessions over 30 days old.
- # Adjust the timespan as desired.
- CLEAN_SESSIONS_SQL='DELETE FROM `sessions` WHERE `timestamp` < (UNIX_TIMESTAMP() - 2592000)'
- OPTIMIZE_CACHES_SQL='OPTIMIZE TABLE `cache` , `cache_filter` , `cache_menu` , `cache_page` , `cache_views` , `sessions`'
- # Note: I have tons of modules installed.
- # I tried cleaning out their table names before posting, but you'll want to double check this SQL.
- OPTIMIZE_REST_SQL='OPTIMIZE TABLE `access` , `accesslog` , `aggregator_category` , `aggregator_category_feed` , `aggregator_category_item` , `aggregator_feed` , `aggregator_item` , `authmap` , `blocks` , `blocks_roles` , `boxes` , `client` , `client_system` , `comments` , `contact` , `files` , `file_revisions` , `filters` , `filter_formats` , `flood` , `history` , `invite` , `menu` , `node` , `node_access` , `node_comment_statistics` , `node_counter` , `node_revisions` , `node_type` , `permission` , `profile_fields` , `profile_values` , `role` , `search_dataset` , `search_index` , `search_total` , `sequences` , `system` , `term_data` , `term_hierarchy` , `term_node` , `term_relation` , `term_synonym` , `url_alias` , `users` , `users_roles` , `variable` , `vocabulary` , `vocabulary_node_types` , `watchdog`'
- # Note: I run this script on a Linode which has limited IO.
- # Adding a short wait between commands lessens the load on the server.
- SLEEP_TIME=5
- echo $CLEAN_SESSIONS_SQL | mysql -u $MYSQL_USERNAME -p$MYSQL_PASSWORD $MYSQL_DATABASE
- sleep $SLEEP_TIME
- echo $OPTIMIZE_CACHES_SQL | mysql -u $MYSQL_USERNAME -p$MYSQL_PASSWORD $MYSQL_DATABASE > /dev/null
- sleep $SLEEP_TIME
- echo $OPTIMIZE_REST_SQL | mysql -u $MYSQL_USERNAME -p$MYSQL_PASSWORD $MYSQL_DATABASE > /dev/null
- echo `date` - Done with Drupal database maintenance
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.