Skip to content

Commit

Permalink
added start/stop backups routes with script
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhbir-singh committed Jul 29, 2018
1 parent 8e6f95e commit 9212f8c
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 43 deletions.
5 changes: 5 additions & 0 deletions app/assets/javascripts/rsnapshot_backups.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,8 @@ $(document).ready(function() {
this.previousSibling.style.display = "";
});
});

$(document).on('click', '#start_backups_button', function(event) {
var submit_btn=document.getElementById("start_backups");
submit_btn.click();
});
14 changes: 13 additions & 1 deletion app/controllers/rsnapshot_backups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def settings
@dest_path = RsnapshotHelper.get_fields("snapshot_root")
@backup_paths = RsnapshotHelper.get_fields("backup")
@cron_job_status = CronTabHelper.check_status
@current_interval = @cron_job_status? CronTabHelper.get_cron_interval : nil
@current_intervals = @cron_job_status? [CronTabHelper.get_cron_interval] : nil
end

def update_backup_directory
Expand Down Expand Up @@ -59,4 +59,16 @@ def stop_automatic_backup
CronTabHelper.remove_cron
end

def start_backups
intervals = params[:interval]
if intervals.size == 0
render :json => {success: false, message: "Error: Select atleast one 'Repeat Duration' to start backups"}
else
render :json => {success: success, message: "Backups Started Successfully !!"}
end
end

def stop_backups
end

end
67 changes: 26 additions & 41 deletions app/views/rsnapshot_backups/settings.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -67,50 +67,35 @@ css:
td
label #{"Repeat Duration"}
td
- unless @cron_job_status
= form_tag rsnapshot_backups_engine.set_interval_path,\
:method => :post,\
:remote => true,\
:id => 'set_interval_form_id',\
:class => 'set_interval_form'
input name="interval" value="daily" type="checkbox" checked="checked"
span.position-absolute.pl-2 Daily
br
input name="interval" value="weekly" type="checkbox"
span.position-absolute.pl-2 Weekly
br
input name="interval" value="Monthly" type="checkbox"
span.position-absolute.pl-2 Monthly

- else
= form_tag rsnapshot_backups_engine.stop_automatic_backup_path,\
:method => :post,\
:remote => true,\
:id => 'stop_backup_form_id',\
:class => 'stop_backup_form'
- if @current_interval == "daily"
input name="interval" value="daily" disabled="disabled" type="checkbox" checked="checked"
- else
input name="interval" value="daily" disabled="disabled" type="checkbox"
span.position-absolute.pl-2 Daily
br
- if @current_interval == "weekly"
input name="interval" value="weekly" disabled="disabled" type="checkbox" checked="checked"
- else
input name="interval" value="weekly" disabled="disabled" type="checkbox"
span.position-absolute.pl-2 Weekly
br
- if @current_interval == "monthly"
input name="interval" value="monthly" disabled="disabled" type="checkbox" checked="checked"
- else
input name="interval" value="monthly" disabled="disabled" type="checkbox"
span.position-absolute.pl-2 Monthly
= form_tag rsnapshot_backups_engine.start_backups_path,\
:method => :post,\
:remote => true,\
:id => 'start_backups_form_id',\
:class => 'start_backups_form'
- if @current_intervals.blank? or @current_intervals.include?("daily")
input name="interval[]" value="daily" type="checkbox" checked="checked"
- else
input name="interval[]" value="daily" type="checkbox"
span.position-absolute.pl-2 Daily
br
- if !@current_intervals.blank? and @current_intervals.include?("weekly")
input name="interval[]" value="weekly" type="checkbox" checked="checked"
- else
input name="interval[]" value="weekly" type="checkbox"
span.position-absolute.pl-2 Weekly
br
- if !@current_intervals.blank? and @current_intervals.include?("monthly")
input name="interval[]" value="monthly" type="checkbox" checked="checked"
- else
input name="interval[]" value="monthly" type="checkbox"
span.position-absolute.pl-2 Monthly
input.p-2.pl-3.pr-3.mt-2#start_backups type="submit" style="display: none;" value="Start Backups"

div style="margin-left:120px;"
= spinner "stop_cron_spinner"
input.p-2.pl-3.pr-3.mt-2#stop_backup_button type="submit" style="cursor:pointer;" value="Stop Backups"
= spinner "start_backups_spinner"
input.p-2.pl-3.pr-3.mt-2#start_backups_button type="button" style="cursor:pointer;" value="Start Backups"
br
span#stop_cron_messages.messages style="display: none"
span#start_backups_messages.messages style="display: none"
br

= javascript_include_tag 'rsnapshot_backups'
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
post 'set_backup_directory' => 'rsnapshot_backups#update_backup_directory'
post 'set_backup_sources' => 'rsnapshot_backups#update_backup_sources'
post 'set_interval' => 'rsnapshot_backups#update_interval'
post 'stop_automatic_backup' => 'rsnapshot_backups#stop_automatic_backup'
post 'start_backups' => 'rsnapshot_backups#start_backups'
post 'stop_backups' => 'rsnapshot_backups#stop_backups'

end
58 changes: 58 additions & 0 deletions script/crontab-util.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

if [[ "$1" == "list" ]]; then
arr=()
if [ -f /etc/cron.weekly/rsnapshot ]; then
arr+=('weekly')
fi
if [ -f /etc/cron.monthly/rsnapshot ]; then
arr+=('monthly')
fi
if [ -f /etc/cron.daily/rsnapshot ]; then
arr+=('daily')
fi
echo "${arr[@]}"

elif [[ "$1" == "reset" ]]; then
if [ -f /etc/cron.weekly/rsnapshot ]; then
rm /etc/cron.weekly/rsnapshot
fi
if [ -f /etc/cron.monthly/rsnapshot ]; then
rm /etc/cron.monthly/rsnapshot
fi
if [ -f /etc/cron.daily/rsnapshot ]; then
rm /etc/cron.daily/rsnapshot
fi

elif [[ "$1" == "add" ]]; then
if [[ "$2" == "weekly" ]]; then
cat > /etc/cron.weekly/rsnapshot << 'EOF'
#!/bin/sh
rsnapshot weekly
EOF
chmod +x /etc/cron.weekly/rsnapshot

elif [[ "$2" == "monthly" ]]; then
cat > /etc/cron.monthly/rsnapshot << 'EOF'
#!/bin/sh
rsnapshot monthly
EOF
chmod +x /etc/cron.monthly/rsnapshot

else
cat > /etc/cron.daily/rsnapshot << 'EOF'
#!/bin/sh
rsnapshot daily
EOF
chmod +x /etc/cron.daily/rsnapshot

fi

elif [[ "$1" == "remove" ]]; then
if [[ "$2" == "weekly" ]]; then
rm /etc/cron.weekly/rsnapshot
elif [[ "$2" == "monthly" ]]; then
rm /etc/cron.monthly/rsnapshot
elif [[ "$2" == "daily" ]]; then
rm /etc/cron.daily/rsnapshot
fi
fi

0 comments on commit 9212f8c

Please sign in to comment.