From: Willy Tarreau Date: Fri, 12 Aug 2022 13:38:20 +0000 (+0200) Subject: MINOR: ring: archive a previous file-backed ring on startup X-Git-Tag: v2.7-dev4~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ded77cc71f3ab4d23251cadb3dc1ba117b096a71;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 678d0af32d..aa167a8264 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -3593,7 +3593,12 @@ backing-file 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 diff --git a/src/sink.c b/src/sink.c index ffb6cf1f97..806eb1706c 100644 --- a/src/sink.c +++ b/src/sink.c @@ -846,6 +846,7 @@ int cfg_parse_ring(const char *file, int linenum, char **args, int kwm) * for 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));