rails_nexus 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +38 -10
  3. data/app/controllers/rails_nexus/stats_controller.rb +0 -126
  4. data/app/views/layouts/rails_nexus/_sidebar_navigation.html.erb +0 -11
  5. data/app/views/layouts/rails_nexus/application.html.erb +1 -12
  6. data/app/views/rails_nexus/stats/index.html.erb +0 -101
  7. data/config/routes.rb +0 -11
  8. data/lib/generators/rails_nexus/templates/migration.rb +0 -82
  9. data/lib/rails_nexus/configuration.rb +0 -45
  10. data/lib/rails_nexus/engine.rb +6 -4
  11. data/lib/rails_nexus/version.rb +1 -1
  12. data/lib/tasks/rails_nexus.rake +0 -80
  13. data/rails_nexus.gemspec +1 -3
  14. metadata +5 -26
  15. data/app/controllers/rails_nexus/backup_controller.rb +0 -119
  16. data/app/jobs/rails_nexus/backup_job.rb +0 -18
  17. data/app/models/rails_nexus/backup.rb +0 -107
  18. data/app/models/rails_nexus/backup_config.rb +0 -189
  19. data/app/services/rails_nexus/backup_runner.rb +0 -62
  20. data/app/services/rails_nexus/backup_service.rb +0 -817
  21. data/app/views/rails_nexus/backup/_form.html.erb +0 -334
  22. data/app/views/rails_nexus/backup/config_history.html.erb +0 -67
  23. data/app/views/rails_nexus/backup/edit.html.erb +0 -15
  24. data/app/views/rails_nexus/backup/history.html.erb +0 -75
  25. data/app/views/rails_nexus/backup/index.html.erb +0 -112
  26. data/app/views/rails_nexus/backup/new.html.erb +0 -15
  27. data/db/seeds/backup_configs.rb +0 -140
  28. data/lib/generators/rails_nexus/backup_generator.rb +0 -70
  29. data/lib/generators/rails_nexus/templates/backup/backup_helper.sh +0 -152
  30. data/lib/generators/rails_nexus/templates/backup/config.rb +0 -27
  31. data/lib/generators/rails_nexus/templates/backup/models/daily_backup.rb +0 -24
  32. data/lib/generators/rails_nexus/templates/backup/models/full_backup.rb +0 -35
  33. data/lib/generators/rails_nexus/templates/backup/models/sync_backup.rb +0 -43
  34. data/lib/generators/rails_nexus/templates/backup/mysql-config/db_config.cnf +0 -15
  35. data/lib/generators/rails_nexus/templates/backup/schedule.rb +0 -28
@@ -1,140 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # ════════════════════════════════════════════════════════════════════
4
- # Backup Config Seed — Migrated from ~/Backup gem models
5
- #
6
- # Run with:
7
- # rails runner db/seeds/backup_configs.rb
8
- #
9
- # Or from the engine:
10
- # rails_nexus:seed_backups rake task
11
- # ════════════════════════════════════════════════════════════════════
12
-
13
- configs = [
14
- {
15
- name: "tti_daily_backup",
16
- description: "TTI Daily MySQL Backup — skip sessions, versions, logged_exceptions",
17
- adapter: "mysql",
18
- database_name: "tti_erp",
19
- host: "localhost",
20
- port: 3306,
21
- username: "ENV[DB_USERNAME]",
22
- password: "ENV[DB_PASSWORD]",
23
- skip_tables: "tti_erp.logged_exceptions,tti_erp.sessions,tti_erp.versions",
24
-
25
- storage_path: "~/dumps",
26
- keep_count: 365,
27
-
28
- compress: true,
29
- bzip2_compress: false,
30
- encrypted: true,
31
- encryption_password: "12upo12e064a3",
32
- gpg_enabled: false,
33
-
34
- rsync_enabled: true,
35
- rsync_host: "172.16.1.232",
36
- rsync_port: 22,
37
- rsync_user: "estudent",
38
- rsync_path: "tti_backups",
39
- rsync_mirror: false,
40
-
41
- s3_enabled: false,
42
-
43
- archive_enabled: false,
44
-
45
- notify_command: "bk-send",
46
- notify_on_success: true,
47
- notify_on_failure: true,
48
- email_notify: false,
49
-
50
- schedule_cron: "0 2 * * *", # daily at 2am
51
- enabled: true
52
- },
53
-
54
- {
55
- name: "tti_full_backup",
56
- description: "TTI Full MySQL Backup — all tables, no skip",
57
- adapter: "mysql",
58
- database_name: "tti_erp",
59
- host: "localhost",
60
- port: 3306,
61
- username: "ENV[DB_USERNAME]",
62
- password: "ENV[DB_PASSWORD]",
63
- skip_tables: "",
64
-
65
- storage_path: "~/dumps",
66
- keep_count: 10,
67
-
68
- compress: true,
69
- bzip2_compress: false,
70
- encrypted: true,
71
- encryption_password: "12upo12e064a3",
72
- gpg_enabled: false,
73
-
74
- rsync_enabled: false,
75
-
76
- s3_enabled: false,
77
-
78
- archive_enabled: false,
79
-
80
- notify_command: "bk-send",
81
- notify_on_success: true,
82
- notify_on_failure: true,
83
- email_notify: false,
84
-
85
- schedule_cron: "0 0 * * 0", # weekly Sunday at midnight
86
- enabled: true
87
- },
88
-
89
- {
90
- name: "tti_sync_backup",
91
- description: "TTI Sync — MySQL dump + RSync push to remote server",
92
- adapter: "mysql",
93
- database_name: "tti_erp",
94
- host: "localhost",
95
- port: 3306,
96
- username: "ENV[DB_USERNAME]",
97
- skip_tables: "tti_erp.logged_exceptions,tti_erp.sessions,tti_erp.versions",
98
-
99
- storage_path: "~/dumps/sync",
100
- keep_count: 1,
101
-
102
- compress: true,
103
- bzip2_compress: false,
104
- encrypted: false,
105
-
106
- rsync_enabled: true,
107
- rsync_host: "198.199.121.213",
108
- rsync_port: 22,
109
- rsync_user: "winner2",
110
- rsync_path: "dumps/tti",
111
- rsync_mirror: false,
112
-
113
- s3_enabled: false,
114
-
115
- archive_enabled: false,
116
-
117
- notify_command: "bk-send",
118
- notify_on_success: true,
119
- notify_on_failure: true,
120
- email_notify: false,
121
-
122
- schedule_cron: "0 3 * * *", # daily at 3am
123
- enabled: true
124
- }
125
- ]
126
-
127
- puts "Seeding #{configs.size} backup configs..."
128
-
129
- configs.each do |attrs|
130
- config = RailsNexus::BackupConfig.find_or_initialize_by(name: attrs[:name])
131
- config.assign_attributes(attrs)
132
-
133
- if config.save
134
- puts " ✓ #{config.name} (#{config.adapter}/#{config.database_name})"
135
- else
136
- puts " ✗ #{config.name}: #{config.errors.full_messages.join(', ')}"
137
- end
138
- end
139
-
140
- puts "Done. #{RailsNexus::BackupConfig.count} configs total."
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators"
4
- require "rails/generators/erb"
5
-
6
- module RailsNexus
7
- module Generators
8
- class BackupGenerator < Rails::Generators::Base
9
- desc "Set up rails_nexus backup directory structure and models"
10
- source_root File.expand_path("templates/backup", __dir__)
11
-
12
- def create_backup_directories
13
- empty_directory "config/backup"
14
- empty_directory "config/backup/models"
15
- empty_directory "config/backup/mysql-config"
16
- empty_directory "storage/rails_nexus/backups"
17
- empty_directory "storage/rails_nexus/backups/sync"
18
- empty_directory "storage/rails_nexus/backups/logs"
19
- end
20
-
21
- def create_config_template
22
- template "config.rb", "config/backup/config.rb"
23
- end
24
-
25
- def create_model_templates
26
- template "models/daily_backup.rb", "config/backup/models/daily_backup.rb"
27
- template "models/full_backup.rb", "config/backup/models/full_backup.rb"
28
- template "models/sync_backup.rb", "config/backup/models/sync_backup.rb"
29
- end
30
-
31
- def create_schedule_template
32
- template "schedule.rb", "config/backup/schedule.rb"
33
- end
34
-
35
- def create_helper_script
36
- template "backup_helper.sh", "bin/rails_nexus-backup"
37
- chmod "bin/rails_nexus-backup", 0o755
38
- end
39
-
40
- def create_mysql_config
41
- template "mysql-config/db_config.cnf", "config/backup/mysql-config/db_config.cnf"
42
- end
43
-
44
- def add_to_gitignore
45
- append_to_file ".gitignore", <<~GITIGNORE unless File.exist?(".gitignore") && File.read(".gitignore").include?("rails_nexus/backups")
46
- \n# RailsNexus backups
47
- storage/rails_nexus/backups/
48
- config/backup/mysql-config/db_config.cnf
49
- GITIGNORE
50
- end
51
-
52
- def show_readme
53
- say ""
54
- say "✅ Backup directory structure created!", :green
55
- say ""
56
- say "Next steps:"
57
- say " 1. Edit config/backup/config.rb with your database credentials"
58
- say " 2. Customize models in config/backup/models/"
59
- say " 3. Install the schedule: whenever --write-crontab"
60
- say " 4. Test: bin/rails_nexus-backup status"
61
- say ""
62
- say "Backup models created:"
63
- say " - daily_backup: Incremental (skips large tables), local + remote"
64
- say " - full_backup: All tables, local only"
65
- say " - sync_backup: Remote sync to backup server"
66
- say ""
67
- end
68
- end
69
- end
70
- end
@@ -1,152 +0,0 @@
1
- #!/bin/bash
2
- # RailsNexus Backup Helper Script
3
- # Generated by: rails generate rails_nexus:backup
4
- #
5
- # Usage:
6
- # ./backup_helper.sh run <model> Run a backup model
7
- # ./backup_helper.sh list List backup files
8
- # ./backup_helper.sh status Show backup health status
9
- # ./backup_helper.sh clean <days> Remove backups older than N days
10
-
11
- set -e
12
-
13
- # Configuration
14
- BACKUP_DIR="${BACKUP_DUMP_PATH:-storage/rails_nexus/backups}"
15
- BUNDLE_PATH="${BUNDLE_PATH:-.bundle}"
16
- RUBY_ENV="${RUBY_ENV:-production}"
17
-
18
- # Colors
19
- RED='\033[0;31m'
20
- GREEN='\033[0;32m'
21
- YELLOW='\033[1;33m'
22
- NC='\033[0m'
23
-
24
- log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
25
- log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
26
- log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
27
-
28
- # Run a backup
29
- run_backup() {
30
- local model="$1"
31
- if [ -z "$model" ]; then
32
- log_error "Usage: $0 run <model_name>"
33
- exit 1
34
- fi
35
-
36
- # Lock to prevent concurrent runs
37
- LOCKFILE="/tmp/rails_nexus_backup_${model}.lock"
38
- exec 200>"$LOCKFILE"
39
- if ! flock -n 200; then
40
- log_warn "Backup '$model' is already running. Skipping."
41
- exit 0
42
- fi
43
-
44
- log_info "Running backup: $model"
45
- cd "$(dirname "$0")/../../.."
46
-
47
- if bundle exec backup perform -t "$model" --triggered_by rails_nexus; then
48
- log_info "Backup '$model' completed successfully."
49
- else
50
- log_error "Backup '$model' FAILED."
51
- exit 1
52
- fi
53
- }
54
-
55
- # List backup files
56
- list_backups() {
57
- local dir="$BACKUP_DIR"
58
- if [ ! -d "$dir" ]; then
59
- log_warn "No backup directory found at: $dir"
60
- exit 0
61
- fi
62
-
63
- echo "Backup files in: $dir"
64
- echo "─────────────────────────────────────────────"
65
- printf "%-40s %10s %s\n" "FILE" "SIZE" "MODIFIED"
66
- echo "─────────────────────────────────────────────"
67
-
68
- find "$dir" -maxdepth 1 -type f -name "*.tar.gz*" -o -name "*.sql.gz*" | sort -r | head -20 | while read -r f; do
69
- size=$(du -h "$f" | cut -f1)
70
- modified=$(stat -c "%y" "$f" 2>/dev/null | cut -d'.' -f1 || date -r "$f" "+%Y-%m-%d %H:%M")
71
- printf "%-40s %10s %s\n" "$(basename "$f")" "$size" "$modified"
72
- done
73
- }
74
-
75
- # Show backup status
76
- show_status() {
77
- local dir="$BACKUP_DIR"
78
- if [ ! -d "$dir" ]; then
79
- echo "Status: NOT_CONFIGURED"
80
- echo "No backup directory at: $dir"
81
- exit 0
82
- fi
83
-
84
- local total_files
85
- total_files=$(find "$dir" -maxdepth 1 -type f | wc -l)
86
- local total_size
87
- total_size=$(du -sh "$dir" 2>/dev/null | cut -f1 || echo "0B")
88
-
89
- local latest_file
90
- latest_file=$(find "$dir" -maxdepth 1 -type f -name "*.tar.gz*" -o -name "*.sql.gz*" 2>/dev/null | sort -r | head -1)
91
-
92
- if [ -z "$latest_file" ]; then
93
- echo "Status: WARNING - No backup files found"
94
- else
95
- local age_hours
96
- age_hours=$(( ($(date +%s) - $(stat -c "%Y" "$latest_file" 2>/dev/null || stat -f "%m" "$latest_file")) / 3600 ))
97
-
98
- if [ "$age_hours" -lt 24 ]; then
99
- echo "Status: HEALTHY"
100
- elif [ "$age_hours" -lt 72 ]; then
101
- echo "Status: WARNING - Last backup ${age_hours}h ago"
102
- else
103
- echo "Status: CRITICAL - Last backup ${age_hours}h ago"
104
- fi
105
- fi
106
-
107
- echo "Files: $total_files"
108
- echo "Size: $total_size"
109
- [ -n "$latest_file" ] && echo "Latest: $(basename "$latest_file")"
110
- }
111
-
112
- # Clean old backups
113
- clean_backups() {
114
- local days="${1:-30}"
115
- local dir="$BACKUP_DIR"
116
-
117
- if [ ! -d "$dir" ]; then
118
- log_warn "No backup directory found at: $dir"
119
- exit 0
120
- fi
121
-
122
- log_info "Removing backups older than $days days..."
123
- find "$dir" -maxdepth 1 -type f -mtime +"$days" -delete
124
- log_info "Cleanup complete."
125
- }
126
-
127
- # Main
128
- case "${1:-help}" in
129
- run)
130
- run_backup "$2"
131
- ;;
132
- list)
133
- list_backups
134
- ;;
135
- status)
136
- show_status
137
- ;;
138
- clean)
139
- clean_backups "$2"
140
- ;;
141
- *)
142
- echo "RailsNexus Backup Helper"
143
- echo ""
144
- echo "Usage: $0 <command> [args]"
145
- echo ""
146
- echo "Commands:"
147
- echo " run <model> Run a backup model (e.g., daily_backup)"
148
- echo " list List recent backup files"
149
- echo " status Show backup health status"
150
- echo " clean [days] Remove backups older than N days (default: 30)"
151
- ;;
152
- esac
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ##
4
- # Backup v5.x Configuration
5
- # Generated by rails_nexus
6
- #
7
- # Documentation: http://backup.github.io/backup
8
- #
9
-
10
- # Logging
11
- # Logger.configure do
12
- # console.quiet = true
13
- # logfile.max_bytes = 2_000_000
14
- # syslog.enabled = true
15
- # syslog.ident = '<%= Rails.application.class.module_parent_name.underscore %>_backup'
16
- # end
17
-
18
- # Storage defaults
19
- # Storage::Local.defaults do |local|
20
- # local.path = 'storage/rails_nexus/backups'
21
- # end
22
-
23
- # Notifier defaults
24
- # Notifier::Mail.defaults do |mail|
25
- # mail.from = 'backup@<%= Rails.application.class.module_parent_name.underscore %>.com'
26
- # mail.to = 'admin@<%= Rails.application.class.module_parent_name.underscore %>.com'
27
- # end
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # Daily Backup - Generated by rails_nexus
4
- # Skips large/temporary tables for faster backups
5
-
6
- Model.new(:daily_backup, '<%= Rails.application.class.module_parent_name %> Daily Backup') do
7
-
8
- ## MySQL [Database]
9
- database MySQL do |db|
10
- db.name = "<%= Rails.configuration.database_configuration[Rails.env]['database'] %>"
11
- db.port = <%= Rails.configuration.database_configuration[Rails.env]['port'] || 3306 %>
12
- db.skip_tables = []
13
- db.additional_options = ["--quick"]
14
- end
15
-
16
- ## Local [Storage]
17
- store_with Local do |local|
18
- local.path = 'storage/rails_nexus/backups'
19
- local.keep = 30
20
- end
21
-
22
- ## Gzip [Compressor]
23
- compress_with Gzip
24
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
- # Full backup template — all tables, local storage only
3
-
4
- model :full_backup do
5
- # Database
6
- database Mysql do |db|
7
- db.name = ENV["DATABASE_NAME"] || "myapp_production"
8
- db.username = ENV["DATABASE_USER"] || "root"
9
- db.password = ENV["DATABASE_PASSWORD"] || ""
10
- db.host = ENV["DATABASE_HOST"] || "localhost"
11
- db.port = (ENV["DATABASE_PORT"] || 3306).to_i
12
- db.dump_options = {
13
- single_transaction: true,
14
- add_lock_tables: false
15
- }
16
- end
17
-
18
- # Compress with Gzip
19
- compress_with Gzip
20
-
21
- # Store locally
22
- store_with Local do |local|
23
- local.path = ENV["BACKUP_DUMP_PATH"] || File.expand_path("storage/rails_nexus/backups", Rails.root)
24
- local.keep = 10
25
- end
26
-
27
- # Notify on failure (optional)
28
- notify_by Mail do |mail|
29
- mail.on_success = false
30
- mail.on_failure = true
31
- mail.from = ENV["BACKUP_MAIL_FROM"] || "backup@example.com"
32
- mail.to = ENV["BACKUP_MAIL_TO"] || "admin@example.com"
33
- mail.smtp = { address: ENV["SMTP_HOST"] || "localhost", port: ENV["SMTP_PORT"] || 587 }
34
- end
35
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
- # Sync backup template — remote sync to backup server
3
-
4
- model :sync_backup do
5
- # Database
6
- database Mysql do |db|
7
- db.name = ENV["DATABASE_NAME"] || "myapp_production"
8
- db.username = ENV["DATABASE_USER"] || "root"
9
- db.password = ENV["DATABASE_PASSWORD"] || ""
10
- db.host = ENV["DATABASE_HOST"] || "localhost"
11
- db.port = (ENV["DATABASE_PORT"] || 3306).to_i
12
-
13
- # Skip large/temporary tables
14
- skip_tables = ENV["BACKUP_SKIP_TABLES"] || "sessions,caches,active_storage"
15
- skip_tables.split(",").each { |t| db.skip_tables << t.strip }
16
- end
17
-
18
- # Compress with Gzip
19
- compress_with Gzip
20
-
21
- # Store locally (staging area)
22
- store_with Local do |local|
23
- local.path = ENV["BACKUP_DUMP_PATH"] || File.expand_path("storage/rails_nexus/backups/sync", Rails.root)
24
- local.keep = 1
25
- end
26
-
27
- # Sync to remote server
28
- notify_by Sync do |sync|
29
- sync.directories do |directory|
30
- directory.path = ENV["BACKUP_DUMP_PATH"] || File.expand_path("storage/rails_nexus/backups/sync", Rails.root)
31
- end
32
-
33
- connection do |conn|
34
- conn.host = ENV["BACKUP_RSYNC_HOST"] || "backup.example.com"
35
- conn.port = ENV["BACKUP_RSYNC_PORT"] || 22
36
- conn.username = ENV["BACKUP_RSYNC_USER"] || "backup"
37
- conn.ssh_options = {
38
- keys: ENV["BACKUP_SSH_KEY"] || File.expand_path("~/.ssh/id_rsa"),
39
- timeout: 30
40
- }
41
- end
42
- end
43
- end
@@ -1,15 +0,0 @@
1
- # RailsNexus Backup MySQL Configuration
2
- # Generated by: rails generate rails_nexus:backup
3
- #
4
- # This file is used by the backup gem for database authentication.
5
- # Keep this file secure and do not commit to version control.
6
-
7
- [client]
8
- user=<%= ENV['DATABASE_USER'] || 'root' %>
9
- password=<%= ENV['DATABASE_PASSWORD'] || '' %>
10
- host=<%= ENV['DATABASE_HOST'] || 'localhost' %>
11
- port=<%= (ENV['DATABASE_PORT'] || 3306).to_i %>
12
- database=<%= ENV['DATABASE_NAME'] || 'myapp_production' %>
13
-
14
- # Dump options
15
- default-character-set=utf8mb4
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
- # RailsNexus Backup Schedule
3
- # Generated by: rails generate rails_nexus:backup
4
- #
5
- # This file is parsed by the BackupService to show schedule info in the UI.
6
- # Actual cron should be installed separately: whenever --write-crontab
7
-
8
- # ─── Backup Schedule ──────────────────────────────────────────────
9
-
10
- # Full backup daily at 2:00 AM (all tables, local only)
11
- every 1.day, at: "2:00 am" do
12
- command "cd #{File.expand_path('../..', __FILE__)} && bundle exec backup perform -t full_backup --triggered_by system"
13
- end
14
-
15
- # Incremental backup every 4 hours (skipping large tables)
16
- every 4.hours do
17
- command "cd #{File.expand_path('../..', __FILE__)} && bundle exec backup perform -t incremental_backup --triggered_by system"
18
- end
19
-
20
- # Remote sync weekly on Sunday at 3:00 AM
21
- every 1.week, at: "3:00 am" do
22
- command "cd #{File.expand_path('../..', __FILE__)} && bundle exec backup perform -t sync_backup --triggered_by system"
23
- end
24
-
25
- # Cleanup old backups monthly
26
- every 1.month, at: "4:00 am" do
27
- command "cd #{File.expand_path('../..', __FILE__)} && bundle exec backup perform -t full_backup --cleanup"
28
- end