Skip to content
Snippets Groups Projects
Commit 3b7c7b87 authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

Make distinction between upgrade and user call.

Allow to use an existing snapshot at upgrade time
parent 5e507e44
No related branches found
No related tags found
No related merge requests found
...@@ -76,7 +76,7 @@ This subcommand make a snapshot called *named* containing a verbatim copy of the ...@@ -76,7 +76,7 @@ This subcommand make a snapshot called *named* containing a verbatim copy of the
`%%livedir%%`, `%%system_log%%` and `$HOME/%%user_log%%` for regular users are not taken into account. `%%livedir%%`, `%%system_log%%` and `$HOME/%%user_log%%` for regular users are not taken into account.
The prefix `update@` is reserved for snapshot names used in automatic upgrade processes. Please consider to choose a different prefix for your personal. snapshot names. The prefix `migrate@` is reserved for snapshot names used in automatic upgrade processes. Please consider to choose a different prefix for your personal snapshot names.
#### Options #### Options
......
...@@ -295,7 +295,7 @@ extern char const *help_snapshot_list ; ...@@ -295,7 +295,7 @@ extern char const *help_snapshot_list ;
#define OPTS_SNAPSHOT_WRAPPER "h" #define OPTS_SNAPSHOT_WRAPPER "h"
#define OPTS_SNAPSHOT_WRAPPER_LEN (sizeof OPTS_SNAPSHOT_WRAPPER - 1) #define OPTS_SNAPSHOT_WRAPPER_LEN (sizeof OPTS_SNAPSHOT_WRAPPER - 1)
#define OPTS_SNAPSHOT_CREATE "h" #define OPTS_SNAPSHOT_CREATE "hs"
#define OPTS_SNAPSHOT_CREATE_LEN (sizeof OPTS_SNAPSHOT_CREATE - 1) #define OPTS_SNAPSHOT_CREATE_LEN (sizeof OPTS_SNAPSHOT_CREATE - 1)
#define OPTS_SNAPSHOT_RESTORE "h" #define OPTS_SNAPSHOT_RESTORE "h"
#define OPTS_SNAPSHOT_RESTORE_LEN (sizeof OPTS_SNAPSHOT_RESTORE - 1) #define OPTS_SNAPSHOT_RESTORE_LEN (sizeof OPTS_SNAPSHOT_RESTORE - 1)
......
...@@ -119,6 +119,7 @@ int ssexec_snapshot_create(int argc, char const *const *argv, ssexec_t *info) ...@@ -119,6 +119,7 @@ int ssexec_snapshot_create(int argc, char const *const *argv, ssexec_t *info)
{ {
log_flow() ; log_flow() ;
short system = 0 ;
char const *snapname = 0 ; char const *snapname = 0 ;
size_t pos = 0, len = 0 ; size_t pos = 0, len = 0 ;
_alloc_stk_(snapdir, SS_MAX_PATH_LEN) ; _alloc_stk_(snapdir, SS_MAX_PATH_LEN) ;
...@@ -140,6 +141,11 @@ int ssexec_snapshot_create(int argc, char const *const *argv, ssexec_t *info) ...@@ -140,6 +141,11 @@ int ssexec_snapshot_create(int argc, char const *const *argv, ssexec_t *info)
info_help(info->help, info->usage) ; info_help(info->help, info->usage) ;
return 0 ; return 0 ;
case 's' :
system = 1 ;
break ;
default : default :
log_usage(info->usage, "\n", info->help) ; log_usage(info->usage, "\n", info->help) ;
} }
...@@ -152,8 +158,9 @@ int ssexec_snapshot_create(int argc, char const *const *argv, ssexec_t *info) ...@@ -152,8 +158,9 @@ int ssexec_snapshot_create(int argc, char const *const *argv, ssexec_t *info)
snapname = *argv ; snapname = *argv ;
if (!str_start_with(snapname, "update@")) if (!system)
log_die(LOG_EXIT_USER, "update@ is a reserved prefix for snapshot names -- please select a different one") ; if (!str_start_with(snapname, "migrate@"))
log_die(LOG_EXIT_USER, "migrate@ is a reserved prefix for snapshot names -- please select a different one") ;
auto_strings(snapdir.s, info->base.s, SS_SNAPSHOT + 1) ; auto_strings(snapdir.s, info->base.s, SS_SNAPSHOT + 1) ;
...@@ -167,8 +174,15 @@ int ssexec_snapshot_create(int argc, char const *const *argv, ssexec_t *info) ...@@ -167,8 +174,15 @@ int ssexec_snapshot_create(int argc, char const *const *argv, ssexec_t *info)
auto_strings(snapdir.s + len, "/", snapname) ; auto_strings(snapdir.s + len, "/", snapname) ;
if (!access(snapdir.s, F_OK)) if (!access(snapdir.s, F_OK)) {
log_dieu(LOG_EXIT_USER, "create snapshot: ", snapdir.s, " -- already exist") ;
if (!system) {
log_dieu(LOG_EXIT_USER, "create snapshot: ", snapdir.s, " -- already exist") ;
} else {
log_warn("snapshot: ", snapdir.s, " already exist -- keeping it") ;
return 0 ;
}
}
len += 1 + strlen(snapname) ; len += 1 + strlen(snapname) ;
...@@ -176,9 +190,6 @@ int ssexec_snapshot_create(int argc, char const *const *argv, ssexec_t *info) ...@@ -176,9 +190,6 @@ int ssexec_snapshot_create(int argc, char const *const *argv, ssexec_t *info)
if (!dir_create_parent(snapdir.s, 0755)) if (!dir_create_parent(snapdir.s, 0755))
log_dieusys(LOG_EXIT_SYS, "create directory: ", snapdir.s) ; log_dieusys(LOG_EXIT_SYS, "create directory: ", snapdir.s) ;
/** attention owner pour SS_USER_DIR*/
if (!info->owner) { if (!info->owner) {
auto_strings(src.s, snapdir.s, SS_SYSTEM_DIR, SS_SYSTEM) ; auto_strings(src.s, snapdir.s, SS_SYSTEM_DIR, SS_SYSTEM) ;
......
...@@ -36,7 +36,7 @@ int ssexec_snapshot_remove(int argc, char const *const *argv, ssexec_t *info) ...@@ -36,7 +36,7 @@ int ssexec_snapshot_remove(int argc, char const *const *argv, ssexec_t *info)
for (;;) for (;;)
{ {
int opt = subgetopt_r(argc, argv, OPTS_SNAPSHOT_RESTORE, &l) ; int opt = subgetopt_r(argc, argv, OPTS_SNAPSHOT_REMOVE, &l) ;
if (opt == -1) break ; if (opt == -1) break ;
switch (opt) { switch (opt) {
......
...@@ -42,7 +42,7 @@ int ssexec_snapshot_wrapper(int argc, char const *const *argv, ssexec_t *info) ...@@ -42,7 +42,7 @@ int ssexec_snapshot_wrapper(int argc, char const *const *argv, ssexec_t *info)
for (;;) { for (;;) {
int opt = subgetopt_r(argc, argv, OPTS_SCANDIR_WRAPPER, &l) ; int opt = subgetopt_r(argc, argv, OPTS_SNAPSHOT_WRAPPER, &l) ;
if (opt == -1) break ; if (opt == -1) break ;
switch (opt) { switch (opt) {
......
...@@ -598,7 +598,7 @@ static void migrate_service_0721(void) ...@@ -598,7 +598,7 @@ static void migrate_service_0721(void)
static void migrate_create_snap_0721(ssexec_t *info) static void migrate_create_snap_0721(ssexec_t *info)
{ {
int argc = 3 ; int argc = 4 ;
int m = 0 ; int m = 0 ;
char const *prog = PROG ; char const *prog = PROG ;
char const *newargv[argc] ; char const *newargv[argc] ;
...@@ -610,12 +610,13 @@ static void migrate_create_snap_0721(ssexec_t *info) ...@@ -610,12 +610,13 @@ static void migrate_create_snap_0721(ssexec_t *info)
info->usage = usage_snapshot_create ; info->usage = usage_snapshot_create ;
newargv[m++] = "snapshot" ; newargv[m++] = "snapshot" ;
newargv[m++] = "update@0.7.2.1" ; newargv[m++] = "-s" ;
newargv[m++] = "migrate@0.7.2.1" ;
newargv[m] = 0 ; newargv[m] = 0 ;
PROG = "snapshot" ; PROG = "snapshot" ;
if (ssexec_snapshot_create(m, newargv, info)) if (ssexec_snapshot_create(m, newargv, info))
log_dieu(LOG_EXIT_SYS, "create snapshot update@0.7.2.1") ; log_dieu(LOG_EXIT_SYS, "create snapshot migrate@0.7.2.1") ;
PROG = prog ; PROG = prog ;
info->help = help ; info->help = help ;
...@@ -626,7 +627,7 @@ void migrate_0721(ssexec_t *info) ...@@ -626,7 +627,7 @@ void migrate_0721(ssexec_t *info)
{ {
log_flow() ; log_flow() ;
log_info("upgrading system from version 0.7.2.1 to ", SS_VERSION) ; log_info("Upgrading system from version: 0.7.2.1 to: ", SS_VERSION) ;
migrate_create_snap_0721(info) ; migrate_create_snap_0721(info) ;
...@@ -634,5 +635,5 @@ void migrate_0721(ssexec_t *info) ...@@ -634,5 +635,5 @@ void migrate_0721(ssexec_t *info)
migrate_service_0721() ; migrate_service_0721() ;
log_info("system successfully updated to version ", SS_VERSION) ; log_info("System successfully upgraded to version: ", SS_VERSION) ;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment