Rake list tasks

August 3, 2008 – 11:37 pm

I can never remember the exact name of a rake task, so I use this all the time:

> rake -T

You can also filter the list of tasks that’s shown. For instance, if you only want to see the database tasks:

> rake -T db

The -T option is handy when you just need to remember the exact wording. It’s not so handy when you’re trying to figure out what the rake task list description is. For that, use -D:

> rake -D
....
rake test:units
    Run tests for units / Run the unit tests in test/unit
....

The output is longer, but you can see the full description. You can also filter by the task name to limit the output so you don’t have to scroll through the full list of tasks.

On Rails 2.1.0, here’s the full rake -T output:

rake db:abort_if_pending_migrations  # Raises an error if there are pending...
rake db:charset                      # Retrieves the charset for the curren...
rake db:collation                    # Retrieves the collation for the curr...
rake db:create                       # Create the database defined in confi...
rake db:create:all                   # Create all the local databases defin...
rake db:drop                         # Drops the database for the current R...
rake db:drop:all                     # Drops all the local databases define...
rake db:fixtures:identify            # Search for a fixture given a LABEL o...
rake db:fixtures:load                # Load fixtures into the current envir...
rake db:migrate                      # Migrate the database through scripts...
rake db:migrate:redo                 # Rollbacks the database one migration...
rake db:migrate:reset                # Resets your database using your migr...
rake db:reset                        # Drops and recreates the database fro...
rake db:rollback                     # Rolls the schema back to the previou...
rake db:schema:dump                  # Create a db/schema.rb file that can ...
rake db:schema:load                  # Load a schema.rb file into the database
rake db:sessions:clear               # Clear the sessions table
rake db:sessions:create              # Creates a sessions migration for use...
rake db:shell                        # Launches the database shell using th...
rake db:structure:dump               # Dump the database structure to a SQL...
rake db:test:clone                   # Recreate the test database from the ...
rake db:test:clone_structure         # Recreate the test databases from the...
rake db:test:prepare                 # Prepare the test database and load t...
rake db:test:purge                   # Empty the test database
rake db:version                      # Retrieves the current schema version...
rake doc:app                         # Build the app HTML Files
rake doc:clobber_app                 # Remove rdoc products
rake doc:clobber_plugins             # Remove plugin documentation
rake doc:clobber_rails               # Remove rdoc products
rake doc:plugins                     # Generate documentation for all insta...
rake doc:rails                       # Build the rails HTML Files
rake doc:reapp                       # Force a rebuild of the RDOC files
rake doc:rerails                     # Force a rebuild of the RDOC files
rake log:clear                       # Truncates all *.log files in log/ to...
rake notes                           # Enumerate all annotations
rake notes:fixme                     # Enumerate all FIXME annotations
rake notes:optimize                  # Enumerate all OPTIMIZE annotations
rake notes:todo                      # Enumerate all TODO annotations
rake rails:freeze:edge               # Lock to latest Edge Rails or a speci...
rake rails:freeze:gems               # Lock this application to the current...
rake rails:unfreeze                  # Unlock this application from freeze ...
rake rails:update                    # Update both configs, scripts and pub...
rake rails:update:configs            # Update config/boot.rb from your curr...
rake rails:update:javascripts        # Update your javascripts from your cu...
rake rails:update:scripts            # Add new scripts to the application s...
rake routes                          # Print out all defined routes in matc...
rake secret                          # Generate a crytographically secure s...
rake stats                           # Report code statistics (KLOCs, etc) ...
rake test                            # Test all units and functionals
rake test:functionals                # Run tests for functionalsdb:test:pre...
rake test:integration                # Run tests for integrationdb:test:pre...
rake test:plugins                    # Run tests for pluginsenvironment / R...
rake test:recent                     # Run tests for recentdb:test:prepare ...
rake test:uncommitted                # Run tests for uncommitteddb:test:pre...
rake test:units                      # Run tests for unitsdb:test:prepare /...
rake tmp:cache:clear                 # Clears all files and directories in ...
rake tmp:clear                       # Clear session, cache, and socket fil...
rake tmp:create                      # Creates tmp directories for sessions...
rake tmp:pids:clear                  # Clears all files in tmp/pids
rake tmp:sessions:clear              # Clears all files in tmp/sessions
rake tmp:sockets:clear               # Clears all files in tmp/sockets

Tags:

Deleting old files

June 1, 2008 – 10:48 pm

Oftentimes, I like to backup SQL databases to a local folder, then include that folder in my backup to tape/disk/network. That way, the backup software doesn’t have to be database aware; it’s just backing up files.

SQL Server allows you to schedule backups and there’s an option to clear out the old backup files, but I’ve found it doesn’t always work quite right. I’d always struggled with a way to do this until I found the FORFILES command.

Now, I’m not sure what version of Windows this appeared it, but I know it’s in Windows Server 2003.

forfiles /p e:\backup /m *.bak /d -2 /c "cmd /c del @file"

The /c option allows you to run any command, so I’m using the del command to delete all files older than a certain date. Certainly, you could do whatever you want, like move them or copy or print their attributes.

The /d is where you specify a date or a number of days. A plus gives you files after that date and a minus gives you files before that date. In my example, files more that two days old are selected to be deleted.

I never had a good way to do this before, so I was always resorting to a script written in another language or a customized batch file (and batch programming is not fun!)


Turn off email logging in Rails

May 27, 2008 – 12:48 am

Oftentimes, I don’t need every single email saved into the log file. When I’m developing, they get in the way. In a production environment, they take up a lot of room make the log harder to read.

So, I normally put this in my environment.rb:

ActionMailer::Base.logger = nil