MINOR: ring: archive a previous file-backed ring on startup

In order to ensure that an instant restart of the process will not wipe
precious debugging information, and to leave time for an admin to archive
a copy of a ring, now upon startup, any previously existing file will be
renamed with the extra suffix ".bak", and any previously existing file
with suffix ".bak" will be removed.
This commit is contained in:
Willy Tarreau 2022-08-12 15:38:20 +02:00
parent 8e87705c21
commit ded77cc71f
2 changed files with 20 additions and 1 deletions

View File

@ -3593,7 +3593,12 @@ backing-file <path>
the "struct ring" that starts at the beginning of the area, and that is
required to recover the area's contents. The file will be created with the
starting user's ownership, with mode 0600 and will be of the size configured
by the "size" directive.
by the "size" directive. Any previously existing file will be renamed with
the extra suffix ".bak", and any previously existing file with suffix ".bak"
will be removed. This ensures that instant restart of the process will not
wipe precious debugging information, and will leave time for an admin to spot
this new ".bak" file and to archive it if needed. This means that the total
storage capacity required will be double of the ring size.
WARNING: there are stability and security implications in using this feature.
First, backing the ring to a slow device (e.g. physical hard drive) may cause

View File

@ -846,6 +846,7 @@ int cfg_parse_ring(const char *file, int linenum, char **args, int kwm)
* for ring <ring>. Existing data are delete. NULL is returned on error.
*/
const char *backing = args[1];
char *oldback;
size_t size;
void *area;
int fd;
@ -862,6 +863,19 @@ int cfg_parse_ring(const char *file, int linenum, char **args, int kwm)
goto err;
}
oldback = NULL;
memprintf(&oldback, "%s.bak", backing);
if (oldback) {
/* try to rename any possibly existing ring file to
* ".bak" and delete remains of older ones. This will
* ensure we don't wipe useful debug info upon restart.
*/
unlink(oldback);
if (rename(backing, oldback) < 0)
unlink(oldback);
ha_free(&oldback);
}
fd = open(backing, O_RDWR | O_CREAT, 0600);
if (fd < 0) {
ha_alert("parsing [%s:%d] : cannot open backing-file '%s' for ring '%s': %s.\n", file, linenum, backing, cfg_sink->name, strerror(errno));