Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Backup database tables in a pre defined order.

Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
  • Loading branch information...
commit 795b1c3a9b2052d0048d7e0770f2d65a610627aa 1 parent bcd6485
@YorickPeterse authored
Showing with 38 additions and 11 deletions.
  1. +38 −11 task/backup.rake
View
49 task/backup.rake
@@ -1,23 +1,50 @@
namespace :db do
+ table_order = [
+ :settings,
+ :user_statuses,
+ :users,
+ :user_groups,
+ :user_groups_users,
+ :permissions,
+ :sections,
+ :section_entry_statuses,
+ :section_entries,
+ :comment_statuses,
+ :comments,
+ :category_groups,
+ :categories,
+ :category_groups_sections,
+ :custom_field_methods,
+ :custom_field_types,
+ :custom_field_groups,
+ :custom_fields,
+ :custom_field_values,
+ :custom_field_groups_sections,
+ :menus,
+ :menu_items,
+ ]
+
desc 'Creates a database independent backup'
task :export do
+ data = {}
- Zen.database.tables.each do |table|
- handle = File.open(
- File.expand_path('../../tmp/%s' % table, __FILE__),
- 'w'
- )
-
- handle.write(Marshal.dump([table, Zen.database[table].all]))
- handle.close
+ table_order.each do |table|
+ data[table] = Zen.database[table].all
end
+
+ handle = File.open(File.expand_path('../../tmp/backup', __FILE__), 'w')
+
+ handle.write(Marshal.dump(data))
+ handle.close
end
desc 'Imports a database backup'
task :import, :backup do |task, args|
- table, rows = Marshal.load(File.open(args[:backup], 'r').read)
+ data = Marshal.load(File.open(args[:backup], 'r').read)
- Zen.database[table].delete
- Zen.database[table].insert_multiple(rows)
+ table_order.each do |table|
+ Zen.database[table].delete
+ Zen.database[table].insert_multiple(data[table])
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.