Commit ae88482d15d37bc5d2effd5b796d606c59a81ba0

Authored by Alexandre Barbosa
1 parent 742fdfb6
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Noosfero: apply patch with backup and restore task

patches/noosfero/0001-Enhance-existing-backup-task-and-add-a-restore-one.patch 0 → 100644
... ... @@ -0,0 +1,137 @@
  1 +From c1918dc6090c011a297bc470c04d4158410e61b8 Mon Sep 17 00:00:00 2001
  2 +From: Antonio Terceiro <terceiro@colivre.coop.br>
  3 +Date: Wed, 11 Feb 2015 19:55:30 -0200
  4 +Subject: [PATCH] Enhance existing backup task and add a restore one
  5 +
  6 +- `rake backup` will now create a tarball with everything that needs to
  7 + be backed up (files + database dump)
  8 +
  9 +- `rake restore BACKUP=/path/to/(...).tar.gz` will restore that backup
  10 + over the current Noosfero instance.
  11 +
  12 +Multi-tenant setups are not supported yet.
  13 +---
  14 + lib/tasks/backup.rake | 111 +++++++++++++++++++++++++++++++++++++++++++++++---
  15 + 1 file changed, 105 insertions(+), 6 deletions(-)
  16 +
  17 +diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake
  18 +index 849d4d6..7e64d17 100644
  19 +--- a/lib/tasks/backup.rake
  20 ++++ b/lib/tasks/backup.rake
  21 +@@ -1,8 +1,107 @@
  22 +-desc "Creates a backup of the user files stored in public/"
  23 +-task :backup do
  24 +- dirs = Dir.glob('public/images/[0-9][0-9][0-9][0-9]') + ['public/articles', 'public/thumbnails', 'public/user_themes'].select { |d| File.exists?(d) }
  25 +- tarball = 'backups/files-' + Time.now.strftime('%Y-%m-%d-%R') + '.tar'
  26 ++task :load_backup_config do
  27 ++ $config = YAML.load_file('config/database.yml')
  28 ++end
  29 ++
  30 ++task :check_backup_support => :load_backup_config do
  31 ++ if $config['production']['adapter'] != 'postgresql'
  32 ++ fail("Only PostgreSQL is supported for backups at the moment")
  33 ++ end
  34 ++end
  35 ++
  36 ++backup_dirs = [
  37 ++ 'public/image_uploads',
  38 ++ 'public/articles',
  39 ++ 'public/thumbnails',
  40 ++ 'public/user_themes',
  41 ++]
  42 ++
  43 ++desc "Creates a backup of the database and uploaded files"
  44 ++task :backup => :check_backup_support do
  45 ++ dirs = backup_dirs.select { |d| File.exists?(d) }
  46 ++
  47 ++ backup_name = Time.now.strftime('%Y-%m-%d-%R')
  48 ++ backup_file = File.join('tmp/backup', backup_name) + '.tar.gz'
  49 ++ mkdir_p 'tmp/backup'
  50 ++ dump = File.join('tmp/backup', backup_name) + '.sql'
  51 ++
  52 ++ database = $config['production']['database']
  53 ++ sh "pg_dump #{database} > #{dump}"
  54 ++
  55 ++ sh 'tar', 'caf', backup_file, dump, *dirs
  56 ++ rm_f dump
  57 ++
  58 ++ puts "****************************************************"
  59 ++ puts "Backup in #{backup_file} !"
  60 ++ puts
  61 ++ puts "To restore, use:"
  62 ++ puts "$ rake restore BACKUP=#{backup_file}"
  63 ++ puts "****************************************************"
  64 ++end
  65 ++
  66 ++def invalid_backup!(message, items=[])
  67 ++ puts "E: #{message}"
  68 ++ items.each do |i|
  69 ++ puts "E: - #{i}"
  70 ++ end
  71 ++ puts "E: Is this a backup archive created by Noosfero with \`rake backup\`?"
  72 ++ exit 1
  73 ++end
  74 ++
  75 ++desc "Restores a backup created previousy with \`rake backup\`"
  76 ++task :restore => :check_backup_support do
  77 ++ backup = ENV["BACKUP"]
  78 ++ unless backup
  79 ++ puts "usage: rake restore BACKUP=/path/to/backup"
  80 ++ exit 1
  81 ++ end
  82 ++
  83 ++ files = `tar taf #{backup}`.split
  84 ++
  85 ++ # validate files in the backup
  86 ++ invalid_files = []
  87 ++ files.each do |f|
  88 ++ if f !~ /tmp\/backup\// && (backup_dirs.none? { |d| f =~ /^#{d}\// })
  89 ++ invalid_files << f
  90 ++ end
  91 ++ end
  92 ++ if invalid_files.size > 0
  93 ++ invalid_backup!("Invalid files found in the backup archive", invalid_files)
  94 ++ end
  95 ++
  96 ++ # find database dump in the archive
  97 ++ dumps = files.select do |f|
  98 ++ File.dirname(f) == 'tmp/backup' && f =~ /\.sql$/
  99 ++ end
  100 ++ if dumps.size == 0
  101 ++ invalid_backup!("Could not find a database dump in the archive.")
  102 ++ elsif dumps.size > 1
  103 ++ invalid_backup!("Multiple database dumps found in the archive:", dumps)
  104 ++ end
  105 ++ dump = dumps.first
  106 ++
  107 ++ database = $config['production']['database']
  108 ++ username = $config['production']['username']
  109 ++
  110 ++ puts "WARNING: backups should be restored to an empty database, otherwise"
  111 ++ puts "data from the backup may not be loaded properly."
  112 ++ puts
  113 ++ puts 'You can remove the existing database and create a new one with:'
  114 ++ puts
  115 ++ puts "$ sudo -u postgres dropdb #{database}"
  116 ++ puts "$ sudo -u postgres createdb #{database} --owner #{username}"
  117 ++ puts
  118 ++ print "Are you sure you want to continue (y/N)? "
  119 ++ response = $stdin.gets.strip
  120 ++ unless ['y', 'yes'].include?(response.downcase)
  121 ++ puts "*** ABORTED."
  122 ++ exit 1
  123 ++ end
  124 ++
  125 ++ sh 'tar', 'xaf', backup
  126 ++ sh "rails dbconsole production < #{dump}"
  127 ++ rm_f dump
  128 +
  129 +- mkdir_p(File.dirname(tarball))
  130 +- sh('tar', 'cf', tarball, *dirs)
  131 ++ puts "****************************************************"
  132 ++ puts "Backup restored!"
  133 ++ puts "****************************************************"
  134 + end
  135 +--
  136 +2.1.4
  137 +
... ...
specs/noosfero/noosfero.spec
1 1 %define writable_dirs javascripts/cache stylesheets/cache articles image_uploads thumbnails
2 2  
3 3 Name: noosfero
4   -Version: 1.1~rc2.3
  4 +Version: 1.1~rc2.4
5 5 Release: 2%{?dist}
6 6 Summary: Social Networking Platform
7 7 Group: Applications/Publishing
... ... @@ -9,6 +9,7 @@ License: AGPLv3
9 9 URL: http://noosfero.org
10 10 Source0: %{name}-%{version}.tar.gz
11 11 Patch0: 0001-Use-as-placeholder-for-current-user-in-URLs.patch
  12 +Patch1: 0001-Enhance-existing-backup-task-and-add-a-restore-one.patch
12 13 BuildArch: noarch
13 14 BuildRequires: noosfero-deps, gettext, po4a
14 15 Requires: noosfero-deps, po4a, tango-icon-theme, memcached
... ... @@ -23,6 +24,7 @@ participate and contribute to this free software project!
23 24 %setup -q
24 25  
25 26 %patch0 -p1
  27 +%patch1 -p1
26 28  
27 29 %build
28 30  
... ...