mirror of
https://github.com/eduardogsilva/routerfleet.git
synced 2025-07-19 10:24:51 +02:00
Fix issue not removing a backup lock in certain conditions.
This commit is contained in:
parent
eee765af96
commit
b92212296d
4 changed files with 142 additions and 90 deletions
|
@ -14,6 +14,7 @@ import unicodedata
|
|||
from routerlib.functions import gen_backup_name, get_router_backup_file_extension
|
||||
from django.conf import settings
|
||||
from user_manager.models import UserAcl
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
@login_required()
|
||||
|
@ -93,6 +94,14 @@ def view_backup_details(request):
|
|||
if not UserAcl.objects.filter(user=request.user).filter(user_level__gte=20).exists():
|
||||
return render(request, 'access_denied.html', {'page_title': 'Access Denied'})
|
||||
backup = get_object_or_404(RouterBackup, uuid=request.GET.get('uuid'))
|
||||
if request.GET.get('action') == 'anticipate':
|
||||
if not backup.success and not backup.error:
|
||||
backup.next_retry = timezone.now()
|
||||
backup.save()
|
||||
messages.success(request, 'Backup task anticipated|Backup task will be retried shortly')
|
||||
else:
|
||||
messages.warning(request, 'Backup task not anticipated|Task is already completed')
|
||||
return redirect(f'/backup/backup_details/?uuid={backup.uuid}')
|
||||
hash_list = [backup.backup_text_hash]
|
||||
backup_list = []
|
||||
for backup_item in RouterBackup.objects.filter(router=backup.router, success=True).order_by('-created'):
|
||||
|
@ -104,7 +113,9 @@ def view_backup_details(request):
|
|||
'backup': backup,
|
||||
'backup_list': backup_list,
|
||||
'page_title': 'Backup Details',
|
||||
'webadmin_settings': webadmin_settings
|
||||
'webadmin_settings': webadmin_settings,
|
||||
'now': timezone.now(),
|
||||
'5_minutes_ago': timezone.now() - timezone.timedelta(minutes=5),
|
||||
}
|
||||
return render(request, 'backup/backup_details.html', context)
|
||||
|
||||
|
@ -188,10 +199,15 @@ def view_backup_delete(request):
|
|||
if not UserAcl.objects.filter(user=request.user).filter(user_level__gte=30).exists():
|
||||
return render(request, 'access_denied.html', {'page_title': 'Access Denied'})
|
||||
backup = get_object_or_404(RouterBackup, uuid=request.GET.get('uuid'))
|
||||
router = backup.router
|
||||
redirect_url = f'/router/details/?uuid={backup.router.uuid}'
|
||||
if request.GET.get('confirmation') == f'delete{backup.id}':
|
||||
backup.delete()
|
||||
messages.success(request, 'Backup deleted successfully')
|
||||
if router.routerstatus.backup_lock:
|
||||
if not RouterBackup.objects.filter(router=router, success=False, error=False).exists():
|
||||
router.routerstatus.backup_lock = None
|
||||
router.routerstatus.save()
|
||||
return redirect(redirect_url)
|
||||
else:
|
||||
messages.warning(request, 'Backup not deleted|Invalid confirmation')
|
||||
|
|
|
@ -35,12 +35,21 @@ def view_router_list(request):
|
|||
def view_router_details(request):
|
||||
router = get_object_or_404(Router, uuid=request.GET.get('uuid'))
|
||||
router_status, _ = RouterStatus.objects.get_or_create(router=router)
|
||||
router_backup_list = router.routerbackup_set.all().order_by('-created')
|
||||
if router_status.backup_lock:
|
||||
if not router_backup_list.filter(success=False, error=False).exists():
|
||||
router_status.backup_lock = None
|
||||
router_status.save()
|
||||
messages.warning(request, 'Backup lock removed|Backup lock was removed as there are no active backup tasks')
|
||||
|
||||
context = {
|
||||
'router': router,
|
||||
'router_status': router_status,
|
||||
'router_backup_list': router.routerbackup_set.all().order_by('-created'),
|
||||
'router_backup_list': router_backup_list,
|
||||
'page_title': 'Router Details',
|
||||
}
|
||||
|
||||
|
||||
return render(request, 'router_manager/router_details.html', context=context)
|
||||
|
||||
|
||||
|
|
|
@ -140,6 +140,6 @@ STATICFILES_DIRS = [
|
|||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
MEDIA_ROOT = '/var/lib/routerfleet/'
|
||||
ROUTERFLEET_VERSION = 7003
|
||||
ROUTERFLEET_VERSION = 7004
|
||||
|
||||
from routerfleet.production_settings import *
|
||||
|
|
|
@ -39,27 +39,27 @@
|
|||
</li>
|
||||
|
||||
|
||||
{% if not backup.success and not backup.error %}
|
||||
<li class="list-group-item">
|
||||
<b><i class="far fa-question-circle" title="This debug information is only displayed while the backup is not finished."></i> Backup Status</b>
|
||||
<span class="float-right">
|
||||
{% if not backup.success and not backup.error %}
|
||||
<li class="list-group-item">
|
||||
<b><i class="far fa-question-circle" title="This debug information is only displayed while the backup is not finished."></i> Backup Status</b>
|
||||
<span class="float-right">
|
||||
{% if backup.success %}
|
||||
<i class="far fa-check-circle text-success"></i>
|
||||
{% elif backup.error %}
|
||||
<i class="far fa-times-circle text-danger"
|
||||
title="{{ backup.error_message }}"></i>
|
||||
{% elif backup.backup_pending_retrieval %}
|
||||
<i class="fas fa-cloud-download-alt text-info"
|
||||
title="Backup pending Retrieval"></i>
|
||||
{% else %}
|
||||
<i class="far fa-clock text-warning"></i>
|
||||
{% endif %}
|
||||
<i class="far fa-check-circle text-success"></i>
|
||||
{% elif backup.error %}
|
||||
<i class="far fa-times-circle text-danger"
|
||||
title="{{ backup.error_message }}"></i>
|
||||
{% elif backup.backup_pending_retrieval %}
|
||||
<i class="fas fa-cloud-download-alt text-info"
|
||||
title="Backup pending Retrieval"></i>
|
||||
{% else %}
|
||||
<i class="far fa-clock text-warning"></i>
|
||||
{% endif %}
|
||||
</span>
|
||||
</li>
|
||||
</li>
|
||||
|
||||
<li class="list-group-item">
|
||||
<b><i class="far fa-question-circle" title="This debug information is only displayed while the backup is not finished."></i> Host Monitoring</b>
|
||||
<span class="float-right">
|
||||
<li class="list-group-item">
|
||||
<b><i class="far fa-question-circle" title="This debug information is only displayed while the backup is not finished."></i> Host Monitoring</b>
|
||||
<span class="float-right">
|
||||
{% if backup.router.monitoring %}
|
||||
{% if backup.router.routerstatus.status_online %}
|
||||
<i class="far fa-check-circle text-success"></i>
|
||||
|
@ -70,34 +70,61 @@
|
|||
Not enabled
|
||||
{% endif %}
|
||||
</span>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b><i class="far fa-question-circle" title="This debug information is only displayed while the backup is not finished."></i> Retry Count</b>
|
||||
<span class="float-right">
|
||||
{{ backup.retry_count }}
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b><i class="far fa-question-circle" title="This debug information is only displayed while the backup is not finished."></i> Retry Count</b>
|
||||
<span class="float-right">
|
||||
<span {% if backup.retry_count > 0 %}class="text-danger"{% endif %}>
|
||||
{{ backup.retry_count }}
|
||||
</span>
|
||||
</span>
|
||||
</li>
|
||||
</li>
|
||||
|
||||
<li class="list-group-item">
|
||||
<b><i class="far fa-question-circle" title="This debug information is only displayed while the backup is not finished."></i> Next Retry</b>
|
||||
<span class="float-right">
|
||||
{% if backup.next_retry %}
|
||||
{% if backup.next_retry > now %}
|
||||
<a href="/backup/backup_details/?uuid={{ backup.uuid }}&action=anticipate">
|
||||
(anticipate)
|
||||
</a>
|
||||
<span class="text-success" style="text-decoration: underline" title="This backup is scheduled to execute after {{ backup.next_retry }}">
|
||||
{{ backup.next_retry }} <i class="far fa-clock"></i>
|
||||
</span>
|
||||
{% else %}
|
||||
<span class="text-info" style="text-decoration: underline" title="This backup is queued to be executed as soon as possible.">
|
||||
{{ backup.next_retry }} <i class="far fa-clock"></i>
|
||||
</span>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
||||
<li class="list-group-item">
|
||||
<b><i class="far fa-question-circle" title="This debug information is only displayed while the backup is not finished."></i> Next Retry</b>
|
||||
<span class="float-right">
|
||||
{{ backup.next_retry|default_if_none:"" }}
|
||||
</span>
|
||||
</li>
|
||||
</li>
|
||||
|
||||
<li class="list-group-item">
|
||||
<b><i class="far fa-question-circle" title="This debug information is only displayed while the backup is not finished."></i> Cron last run</b>
|
||||
<span class="float-right">
|
||||
{{ webadmin_settings.cron_last_run }}
|
||||
<li class="list-group-item">
|
||||
<b><i class="far fa-question-circle" title="This debug information is only displayed while the backup is not finished."></i> Cron last run</b>
|
||||
<span class="float-right">
|
||||
{% if webadmin_settings.cron_last_run %}
|
||||
{% if webadmin_settings.cron_last_run < 5_minutes_ago %}
|
||||
<span class="text-danger" style="text-decoration: underline" title="Your cron tasks are not being executed properly.">
|
||||
{{ webadmin_settings.cron_last_run }}
|
||||
</span>
|
||||
{% else %}
|
||||
|
||||
{{ webadmin_settings.cron_last_run }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</span>
|
||||
</li>
|
||||
</li>
|
||||
|
||||
<li class="list-group-item">
|
||||
<b><i class="far fa-question-circle" title="This debug information is only displayed while the backup is not finished."></i> Error message</b>
|
||||
<span class="float-right">
|
||||
<li class="list-group-item">
|
||||
<b><i class="far fa-question-circle" title="This debug information is only displayed while the backup is not finished."></i> Error message</b>
|
||||
<span class="float-right">
|
||||
{{ backup.error_message }}
|
||||
</span>
|
||||
</li>
|
||||
</li>
|
||||
|
||||
|
||||
{% endif %}
|
||||
|
@ -136,16 +163,16 @@
|
|||
<b>Download</b>
|
||||
<span class="float-right">
|
||||
{% if backup.backup_text %}
|
||||
<a href="/backup/download/?uuid={{ backup.uuid }}&type=text" download>
|
||||
<a href="/backup/download/?uuid={{ backup.uuid }}&type=text" download>
|
||||
Text
|
||||
</a>
|
||||
{% if backup.backup_binary %} - {% endif %}
|
||||
{% if backup.backup_binary %} - {% endif %}
|
||||
{% endif %}
|
||||
{% if backup.backup_binary %}
|
||||
<a href="/backup/download/?uuid={{ backup.uuid }}&type=binary" download>
|
||||
{% if backup.backup_binary %}
|
||||
<a href="/backup/download/?uuid={{ backup.uuid }}&type=binary" download>
|
||||
Binary
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</span>
|
||||
</li>
|
||||
|
||||
|
@ -166,7 +193,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-primary card-outline">
|
||||
<div class="card card-primary card-outline">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">
|
||||
Latest Configuration changes
|
||||
|
@ -188,25 +215,25 @@
|
|||
<tbody>
|
||||
{% for compare_backup in backup_list %}
|
||||
<tr>
|
||||
<td class="min-width">
|
||||
<td class="min-width">
|
||||
<a href="/backup/backup_details/?uuid={{ compare_backup.uuid }}">
|
||||
{{ compare_backup.id }}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
{% if compare_backup.finish_time %}
|
||||
{{ compare_backup.finish_time }}
|
||||
{% else %}
|
||||
{{ compare_backup.created }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if compare_backup.finish_time %}
|
||||
{{ compare_backup.finish_time }}
|
||||
{% else %}
|
||||
{{ compare_backup.created }}
|
||||
{% endif %}
|
||||
|
||||
</td>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<a href="/backup/compare/?uuid={{ backup.uuid }}&compare_uuid={{ compare_backup.uuid }}">
|
||||
Compare
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="/backup/compare/?uuid={{ backup.uuid }}&compare_uuid={{ compare_backup.uuid }}">
|
||||
Compare
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
@ -214,7 +241,7 @@
|
|||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='col-xl-8'>
|
||||
<div class="card card-primary card-outline">
|
||||
|
@ -237,16 +264,16 @@
|
|||
|
||||
{% block custom_page_scripts %}
|
||||
|
||||
<script>
|
||||
function openCommandDialog(element) {
|
||||
var command = element.getAttribute('data-command');
|
||||
var confirmation = prompt("Please type 'delete{{ backup.id }}' to proceed.");
|
||||
if (confirmation) {
|
||||
var url = "/backup/delete/?uuid={{ backup.uuid }}&action=delete&confirmation=" + encodeURIComponent(confirmation);
|
||||
window.location.href = url;
|
||||
<script>
|
||||
function openCommandDialog(element) {
|
||||
var command = element.getAttribute('data-command');
|
||||
var confirmation = prompt("Please type 'delete{{ backup.id }}' to proceed.");
|
||||
if (confirmation) {
|
||||
var url = "/backup/delete/?uuid={{ backup.uuid }}&action=delete&confirmation=" + encodeURIComponent(confirmation);
|
||||
window.location.href = url;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
||||
|
||||
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue