Skip to content
GitLab
About GitLab
GitLab: the DevOps platform
Explore GitLab
Install GitLab
How GitLab compares
Get started
GitLab docs
GitLab Learn
Pricing
Talk to an expert
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Projects
Groups
Snippets
Sign up now
Login
Sign in
Toggle navigation
Menu
Open sidebar
project
hosting_site_backup_manager
Commits
8e1cd180
Commit
8e1cd180
authored
Nov 07, 2014
by
Guillaume Boudrias
Browse files
Issue
#2154813
by ergonlogic, helmo: Add hosting_backup_window module
parent
9428a8e0
Changes
4
Hide whitespace changes
Inline
Side-by-side
hosting_backup_queue/hosting_backup_queue.module
View file @
8e1cd180
...
...
@@ -35,9 +35,16 @@ function hosting_backup_queue_hosting_queues() {
*/
function
hosting_backup_queue_queue
(
$count
)
{
$sites
=
_hosting_backup_queue_get_outstanding_backups
(
$count
);
if
(
module_exists
(
'hosting_backup_window'
))
{
if
(
!
hosting_backup_window_is_allowed_time_window
())
{
return
;
}
}
foreach
(
$sites
as
$site_id
)
{
if
(
$task
=
_hosting_backup_queue_get_backup_task
(
$site_id
))
{
drush_invoke_process
(
'@self'
,
"hosting-task"
,
array
(
$task
->
nid
),
array
(
'strict'
=>
FALSE
),
array
(
'fork'
=>
TRUE
));
drush_invoke_process
(
'@self'
,
"hosting-task"
,
array
(
$task
->
nid
),
array
(
'strict'
=>
FALSE
),
array
(
'fork'
=>
TRUE
));
}
}
}
...
...
hosting_backup_window/hosting.feature.backup_window.inc
0 → 100644
View file @
8e1cd180
<?php
/**
* @file
* The hosting feature definition for the backup window.
*/
/**
* Register a hosting feature with Aegir.
*
* This will be used to generate the 'admin/hosting' page.
*
* @return
* associative array indexed by feature key.
*/
function
hosting_backup_window_hosting_feature
()
{
$features
[
'backup_window'
]
=
array
(
// title to display in form
'title'
=>
t
(
'Backup window'
),
// description
'description'
=>
t
(
'Allows backups to be restricted to certain time periods.'
),
// initial status ( HOSTING_FEATURE_DISABLED, HOSTING_FEATURE_ENABLED, HOSTING_FEATURE_REQUIRED )
'status'
=>
HOSTING_FEATURE_DISABLED
,
// module to enable/disable alongside feature
'module'
=>
'hosting_backup_window'
,
// associate with a specific node type.
// 'node' => 'nodetype',
// which group to display in ( null , experimental )
'group'
=>
'experimental'
);
return
$features
;
}
hosting_backup_window/hosting_backup_window.info
0 → 100644
View file @
8e1cd180
name
=
Backup
window
description
=
Allows
restricting
the
backup
queue
to
only
run
at
certain
times
core
=
6.
x
package
=
Hosting
dependencies
[]
=
hosting_site
dependencies
[]
=
hosting_site_backup_manager
dependencies
[]
=
hosting_backup_queue
hosting_backup_window/hosting_backup_window.module
0 → 100644
View file @
8e1cd180
<?php
// if (hosting_backup_window_is_allowed_time_window()) {
/**
* Checks whether we are currently within the allowed time window for backups.
*
* @TODO : Consider nightly backups.
*/
function
hosting_backup_window_is_allowed_time_window
(
$time
=
NULL
)
{
if
(
$time
===
NULL
)
{
$time
=
time
();
}
$today
=
date
(
"D"
,
time
());
$start_time
=
variable_get
(
'hosting_backup_window_time_window_start'
,
'00:00'
);
$end_time
=
variable_get
(
'hosting_backup_window_time_window_end'
,
'23:59'
);
// Date field shenanigans
if
(
empty
(
$start_time
))
{
$start_time
=
strtotime
(
'00:00'
);
// Midnight "this morning"
}
else
{
$start_time
=
strtotime
(
$start_time
);
}
if
(
empty
(
$end_time
))
{
$end_time
=
strtotime
(
'23:59'
);
// Midnight "this morning"
}
else
{
$end_time
=
strtotime
(
$end_time
);
}
/*
dsm('Evaluated time: ' . date('m/d/Y h:i:s a', time()));
dsm('Start time : ' . date('m/d/Y h:i:s a', $start_time));
dsm('End time : ' . date('m/d/Y h:i:s a', $end_time));
dsm('Today: ' . $today );
*/
if
(
$time
<
$start_time
)
{
// Before the start time
return
FALSE
;
}
if
(
$time
>
$end_time
)
{
// After the end time
return
FALSE
;
}
$allowed_days_array
=
variable_get
(
'hosting_backup_window_time_window_days'
,
NULL
);
// All days allowed by default, don't process if variable is not set
if
(
$allowed_days_array
!==
NULL
)
{
if
(
!
in_array
(
$today
,
$allowed_days_array
))
{
return
FALSE
;
}
}
return
TRUE
;
}
/**
* Returns the backup task to run for a given site.
*/
function
_hosting_backup_window_get_backup_task
(
$site
)
{
// Ensure that we have a backup task to run
return
hosting_add_task
(
$site
,
'backup'
,
array
(
'description'
=>
t
(
'Automated backup'
)));
}
/**
* Implementation of hook_form_alter()
*/
function
hosting_backup_window_form_alter
(
&
$form
,
$form_state
,
$form_id
)
{
if
(
$form_id
==
'hosting_site_backup_manager_settings'
&&
user_access
(
'administer hosting backup queue'
))
{
$days_array
=
drupal_map_assoc
(
array
(
'Mon'
,
'Tue'
,
'Wed'
,
'Thu'
,
'Fri'
,
'Sat'
,
'Sun'
));
$server_time_message
=
t
(
'The current server time is @time'
,
array
(
'@time'
=>
date
(
"H:i"
)));
$form
[
'backup_window'
]
=
array
(
'#type'
=>
'fieldset'
,
'#title'
=>
t
(
'Backup window'
),
'#collapsible'
=>
TRUE
,
'#collapsed'
=>
TRUE
,
'#weight'
=>
-
10
,
);
$form
[
'backup_window'
][
'backup_window_start'
]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Start doing automated backups at'
),
'#description'
=>
t
(
'Format: 00:00. '
)
.
$server_time_message
,
'#default_value'
=>
variable_get
(
'hosting_backup_window_time_window_start'
,
'00:00'
),
'#maxlength'
=>
5
,
'#size'
=>
6
,
);
$form
[
'backup_window'
][
'backup_window_end'
]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Stop doing automated backups'
),
'#description'
=>
t
(
'Format: 23:59. '
)
.
$server_time_message
,
'#default_value'
=>
variable_get
(
'hosting_backup_window_time_window_end'
,
'23:59'
),
'#maxlength'
=>
5
,
'#size'
=>
6
,
);
$form
[
'backup_window'
][
'backup_window_days'
]
=
array
(
'#title'
=>
t
(
'Only do backups on those days'
),
'#type'
=>
'select'
,
'#options'
=>
$days_array
,
'#multiple'
=>
TRUE
,
'#size'
=>
7
,
'#default_value'
=>
variable_get
(
'hosting_backup_window_time_window_days'
,
$days_array
),
);
$form
[
'#validate'
][]
=
'hosting_backup_window_time_window_form_validate'
;
$form
[
'#submit'
][]
=
'hosting_backup_window_time_window_form_submit'
;
}
}
function
hosting_backup_window_time_window_form_validate
(
&
$form
,
&
$form_state
)
{
$date_format
=
'H:i'
;
$values
=
$form_state
[
'values'
];
if
(
!
empty
(
$values
[
'backup_window_start'
]))
{
if
(
strtotime
(
$values
[
'backup_window_start'
])
==
0
)
{
form_set_error
(
'backup_window_start'
,
t
(
'Invalid start time'
));
}
}
if
(
!
empty
(
$values
[
'backup_window_end'
]))
{
if
(
strtotime
(
$values
[
'backup_window_end'
])
==
0
)
{
form_set_error
(
'backup_window_end'
,
t
(
'Invalid end time'
));
}
}
}
function
hosting_backup_window_time_window_form_submit
(
&
$form
,
&
$form_state
)
{
$values
=
$form_state
[
'values'
];
$value_start
=
''
;
if
(
!
empty
(
$values
[
'backup_window_start'
]))
{
variable_set
(
'hosting_backup_window_time_window_start'
,
$values
[
'backup_window_start'
]);
}
else
{
variable_del
(
'hosting_backup_window_time_window_start'
);
}
$value_end
=
''
;
if
(
!
empty
(
$values
[
'backup_window_end'
]))
{
variable_set
(
'hosting_backup_window_time_window_end'
,
$values
[
'backup_window_end'
]);
}
else
{
variable_del
(
'hosting_backup_window_time_window_end'
);
}
variable_set
(
'hosting_backup_window_time_window_days'
,
$values
[
'backup_window_days'
]);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment