University of Oregon

Drupal DB backup bash script with Drush and Git

I like to make incremental backups of my drupal databases. To do that I’ve tried combine the best practices* into one bash script that I can run periodically and easily.
The end result is a bash function that’s easy and user friendly.
It works by leveraging Drush aliases and the drush sql-dump command in combination with git.

Usage is simple. From the command line:

$ dg_db_backup drush.alias "commit message" 

Note: dg_db_backup -> drush git database backup
(more…)

Php on UO Shell the bare minimum

I wanted to redirect a shell site to a new WPMU site on the UO’s Web Site Lite setup. http://sites.uoregon.edu/. Web Site Lite is great, but it has limitations. Since I wanted to redirect all the old links to the new site I set up a .htaccess file that bounces all requests from the old site to the new site.
To do just that I could use:

Redirect 301 /~oa/ http://oa.uoregon.edu/ #works but I'd like to remove .php and .html

But I wanted to remove the file extensions before redirecting.
For that I needed to use Mod Rewrite. Which means I needed to enable php on shell.
There used to be a post: Easy PHP on shell by Tristan but that page is down so I looked at my other domain on shell and it turns out, all I needed to do is put a php.cgi file in the public_html folder and add some lines to the top of my .htaccess file. Now the mod_rewrite script can run! (more…)

Drupal & shell bookmarklet for updating modules 5 (updated – mulitple dbs, backup only option)

*Note: This is a follow up to the posts:

First off: here is the bookmarklet:
This first one is bare-bones; you get prompted for every var:
Install Mods Prompt

This next one needs to be customized to contain your directory and server data but then you don’t have to answer questions every time:
Install mods mysite
You can use http://subsimple.com/bookmarklets/jsbuilder.htm to edit the bookmarklet and set the defaults before saving it.

Now for the details:
I’ve refined the module install bookmarklets once again.
As with the previous versions: click the bookmarklet on a Drupal project page, pick the module and get the ssh script to install it.
Click the bookmarklet on your admin/reports/updates and get the code to install all the recommended updates.
This is tailored to work on our server and doesn’t work on our shell environment. Although it could with some modifications.
At this point you need to cut and paste the file and database backup lines independently because they each require passwords.
I’ll work towards a version that allows a single cut and paste.
(more…)

Drupal & shell bookmarklet for updating modules 4 (updated – bookmarklet w/ base code)

*Note: A new post is available here: Drupal & shell bookmarklet for updating modules 5 (updated – mulitple dbs, backup only option)

This is a follow up to the posts:

Here they are.
This first one is bare-bones; you get prompted for every var:
Install Mods Prompt

This one needs to be customized to contain your directory and server data but then you don’t have to answer questions every time:
Install mods mysite
You can use http://subsimple.com/bookmarklets/jsbuilder.htm to edit the bookmarklet and set the defaults before saving it.

Details
I’ve refined the module install bookmarklets again.
I considered abandoning these in favor of the drush component but drush requires php 5.2 and we’re still using 5.1 at this point.
This works pretty well for me. Click it on a Drupal project page, pick the module and get the ssh to install it.
Click it on the admin/reports/updates and get the code to install all the recommended updates
(more…)

How to Set-up a Crontab File

Thank goodness for CrunchBang ~ Howto Set-up a Crontab File.

I’ve been editing existing crontab files for months but never set up my own for drupal.

While there’s a lot of documentation with drupal on what cron jobs are and how you might want to configure one there’s some steps missing.
(more…)

Drupal & shell bookmarklet for updating modules 3 (updated – wget bookmarklets)

*Note: A new post is available here: Drupal & shell bookmarklet for updating modules 5 (updated – mulitple dbs, backup only option)

This is a follow up to the post: Drupal & shell bookmarklet for updating modules
Also see: Drupal & shell bookmarklet for updating modules 2 ->just Recommended

I’ve refined the module install bookmarklets. These put the vars you might want to customize at the top so you aren’t changing the details every time:
For example:

  var siteDirName='site_directory';
  var siteBasePath='/var/www/html/';
  var backupBasePath='/home/yourName/drupal_backup/';
  var dbUser='drupal6-db-user';
  var dbName='drupal6-db';
  var serverName='myServer';
 

You can use http://subsimple.com/bookmarklets/jsbuilder.htm to edit the bookmarklet and set the defaults to suit your set up.

I use this first one on the admin/reports/updates page (where I know jQuery is installed) to capture all the ‘recommended’ updates and output them to a shell script that I cut and paste into terminal. Each update is fetched via wget, unpacked into my modules directory, overwriting the old module and then the zip file is removed.

After all the files have been processed, the directory is listed and the db and site is backed up.
Then I can begrudgingly go to the update page and run the script.

install all mods jQuery var

javascript:(function(){var siteDirName='site_directory';var siteBasePath='/var/www/html/';var backupBasePath='/home/yourName/drupal_backup/';var dbUser='drupal6-db-user';var dbName='drupal6-db';var serverName='myServer';var date=new%20Date();var saveDate=date.getMonth()+1+'-'+date.getDate()+'-'+date.getFullYear();var connect=confirm('Would%20you%20like%20to%20include%20the%20connection%20information?');var shellLocation=prompt('What%20is%20the%20location%20of%20your%20install%20directory?',siteBasePath+siteDirName+'/sites/all/modules/');var shellText=%22%22;if(connect){shellText='##ssh%20'+serverName;}if(shellLocation!==null){shellText=shellText+'<br />cd%20'+shellLocation;}with($('table.version-recommended%20td%20li.update-download%20a').each(function(){q=this.href.toString().split('/').pop();if(q!==%22%22&amp;&amp;this.href!=%22%22){shellText=shellText+%22<br />wget%20%22+unescape(this.href);shellText=shellText+%22<br />gzip%20-dc%20%22+escape(q)+%22%20|%20tar%20-x%22;shellText=shellText+%22<br />rm%20%22+escape(q);}}));if(connect){shellText=shellText+%22<br />wait%22;shellText=shellText+%22<br />ls%20-al%22;shellText=shellText+%22<br />sudo%20tar%20-c%20--checkpoint%20%22+siteBasePath+siteDirName+%22/%20|%20bzip2%20&gt;%20%22+backupBasePath+siteDirName+saveDate+%22.tar.bz2;%20%20##Backupfiles%22;shellText=shellText+%22<br />mysqldump%20-u%20%22+dbUser+%22%20-p%20%22+dbName+%22%20&gt;%20%22+backupBasePath+siteDirName+saveDate+%22.sql;%20%20##BackupDB%22;}if(shellText!==%22%22){if(window.clipboardData){window.clipboardData.setData('Text',shellText);}else{wnd=open('','Shell_Command','width=650,height=400,top=0,left=0,scrollbars,resizable');with(wnd.document){writeln('<pre>');writeln(shellText);writeln('</pre>');}wnd.document.close();}}/*if%20shellText!==%22%22*/})()

You’ll have to paste that in to your url bar as something about the syntax breaks the link in wordpress…
But you can grab the bookmarklet here: http://uoregon.edu/~vid/v_drupal_bookmarks.php. It’s the first one in the list.
(more…)

Drupal & shell bookmarklet for updating modules 2 ->just Recommended

Note *A new post is available here: Drupal & shell bookmarklet for updating modules 5 (updated – mulitple dbs, backup only option)

I just posted about a bookmarklet I wrote to help with processing drupal module updates.
After looking at the update (admin/reports/updates) page today. I noticed that there are occasionally more than one download link for each module. Some marked ‘Also available:’ as well as ‘Development Version’. So the new challenge is finding the recommended one.

After a bit of thinking I worked out a new bookmarklet. This time capitalizing on jQuery to grab the desired links:
Install all mods jQuery

It’s quite a bit shorter than the last version. 1164 characters vs. 2433 characters.
I would suspect that if I knew more jQuery I could replace quite a bit more as well; though most of the savings are related to the lack of selection highlight or direct entry support. The other bookmarks (wget in particular) will still be quite handy for installing from the Drupal site. (more…)

Drupal & shell bookmarklet for updating modules

*Note: A new post is available here: Drupal & shell bookmarklet for updating modules 5 (updated – mulitple dbs, backup only option)
There is a follow up to this post here: Drupal & shell bookmarklet for updating modules 2 ->just Recommended

Here are some bookmarks I’ve been working on to help make Drupal module updates easier.

These are currently just for my convenience. Which means I haven’t done any cross-browser testing. I only use them in Firefox on Mac at this point. Feel free to make use of the code and update it as you see fit. Personally I’ve created versions without all the pop up prompts for my primary sites.

The idea behind these is that when you are on your admin/reports/updates page you can choose a download and get the script you need to get the job done without having to type it from scratch each time. I’ve been using the ‘Install all mods wget’ one to download and install new modules from the Drupal site or Open Atrium as well. Infact anytime I see a tar.gz link that I want to unzip and install I click this one.
(more…)