Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jn1xH-00066A-HB for pgsql-general@arkaria.postgresql.org; Sun, 21 Jun 2020 15:32:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jn1xG-0006Vh-EB for pgsql-general@arkaria.postgresql.org; Sun, 21 Jun 2020 15:32:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jn1xG-0006Va-4V for pgsql-general@lists.postgresql.org; Sun, 21 Jun 2020 15:32:22 +0000 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jn1xD-0005JJ-Ve for pgsql-general@lists.postgresql.org; Sun, 21 Jun 2020 15:32:21 +0000 Received: by mail-ot1-x32d.google.com with SMTP id n6so11148288otl.0 for ; Sun, 21 Jun 2020 08:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=X1IwVMsr1Q3oSPBkixaHr0Sr4QSLo99//ZYcd/XGPdY=; b=A4r2hv5zhzCwCIPyaQ0OBZsV5cPCt/mk2BwhykU4AP83yYo5cKFT4PZ0BFAWbxXOhN ZlW8GYYWerTWy8JFFaumBblaI1w/txeaTSG/YFs3+OOZZXtaobVXgWuXrMiRIojD3VIu EjFD78loSQygqjgvEGcI2blBKAnEdfn6ewQeHW81u+EZdHyZKTpn7O6Pl+iaC0v03Mo3 haz/URkCceqweANTN0RtXV5YFwbopy+W6oBHJ677cTPvdif3HuLBimvdhASm51DXRedb WMRUGXDTxM3Uv7RYkl+9qna7Ahzc3rEpzQSoBCBlCaxmGwosfU8IaqaZAE9NT38/vJYW Jx1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=X1IwVMsr1Q3oSPBkixaHr0Sr4QSLo99//ZYcd/XGPdY=; b=pQa/IFKS3QP3y/iZ0V0xYd1Dv4PBKONsNHtQAUwT2wX8DtAPICUQ8eWjjr8o4T1VEj oVLbCPUk3YoN9qFcDDxJtbZ4yOXxjGc1z7AK5d4c4V7PYlNPVjYlKPY/UI1Hn1jXtmUK M5wnCfR9CkSjdx9Ryx0+F1VI0Wm5RCpHuXG7g8DX0FivZRyLBdxcbc0DTxM1gCVF/tl8 ipzFuME8XfrW2EgSRbllkmf+zYc+BMNdDbRKRz/D2TWQ+B+mk3zK8zImNPeGMesjWfMS MniYbqdOw+y6J5aZ+3Tg7SThWcqIZRW+NLtjuBwEnaH9rmHqEVkKjJ0TOKQZjtQBxS0h BmzA== X-Gm-Message-State: AOAM531uWjRrAsXYABQvwAaH+2gjFM/IMmxsvbNnh+DhdXfi4stQSqJJ KJz9prgEazEUT50VJPOkeuCZP/RJl/rgag== X-Google-Smtp-Source: ABdhPJw/bIkbryW5NyNUfZgPzREes51g3YZL2RJ5RNxjLXgaJHM8KxKYGr22XhYT99hEUc4OkS8xMw== X-Received: by 2002:a05:6830:1df5:: with SMTP id b21mr10972395otj.338.1592753537725; Sun, 21 Jun 2020 08:32:17 -0700 (PDT) Received: from [192.168.1.10] (ip70-186-126-197.no.no.cox.net. [70.186.126.197]) by smtp.googlemail.com with ESMTPSA id m13sm2730460oou.25.2020.06.21.08.32.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Jun 2020 08:32:17 -0700 (PDT) Subject: Re: The backup API and general purpose backup software To: pgsql-general@lists.postgresql.org References: <20200621132843.GB21591@hjp.at> From: Ron Message-ID: Date: Sun, 21 Jun 2020 10:32:16 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200621132843.GB21591@hjp.at> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter, I don't understand that last step "5. copy the result from the previous step to the backup medium."  It seems to be a duplication of "3. copy the contents of the data directory to the backup medium". On 6/21/20 8:28 AM, Peter J. Holzer wrote: > This is inspired by the thread with the subject "Something else about > Redo Logs disappearing", but since that thread is already quite long, > since I have lost track what exactly "Peter"'s problem is and since his > somewhat belligerent tone makes it unappealing to reread the whole > thread I'll attempt a fresh start. > > To make a full backup with the "new" (non-exclusive) API, a software > must do the following > > 1. open a connection to the database > > 2. invoke pg_start_backup('label', false, false) in the connection from > step 1. > > 3. copy the contents of the data directory to the backup medium > > 4. invoke pg_stop_backup(false, true) in the connection from step 1. > > 5. copy the result from the previous step to the backup medium. > > (It is assumed that any archived WALs are also archived in a manner that > they can be restored together with this backup. If this is not the case > adding them to the backup would be step 6.) > > So far so good and writing a program which implements this should not > pose a great difficulty. > > General purpose backup software often assumes that it can perform a > backup in three steps: > > 1. Invoke a pre-backup script. > > 2. Copy files to the backup medium in such a way that they can be > identified as a group and be restored together and without mixing > them with data from another backup session. > > 3, Invoke a post-backup script. > > (I have to admit that is has been a long time since I've looked at any > backup system in any detail. Doubtlessly many have a more complicated > model, but I'm fairly confident that this is still the lowest common > denominator.) > > Now we have two problems. > > The first is that the pre-backup script has to exit before the proper > backup can begin, but it also has to open a connection which will stay > open during the backup because it will be needed in the post-backup > script again. This can be solved by starting a background process which > keeps the connection open and providing some communication channel > (perhaps a Unix pipe) for the post-backup script to communicate with > this background process. A bit awkward, but no great deal. > > The second problem is that the post-backup script will only be called > after the backup is finished. So the information returned by pg_stop_backup > cannot be included in the backup which makes the backup useless. This is > indeed serious, and I don't see a way around this in this simple model. > > But there is a workaround: Split the backup. > > I am assuming that the backup software uses a unique ID to identify each > backup and passes that ID to the pre-backup and post-backup script. > This ID is used as the label in the call to pg_start_backup(). > It is also included in the information returned by pg_stop_backup(). So > the post-backup script stores that information in a different place > (maybe including the ID in the filename(s) to avoid conflicts and for > redundancy) and then triggers a backup of that place (or alternatively > that can be backed up independently). > > To restore a backup, you will then also need two steps: > > 1) Restore the summary information from the second backup. Inspect the > backup_label to find the ID of the backup of the data. > > 2) Restore that backup > > (3) Put the backup label where it belongs, make sure the archived WALs > are accessible and start the database > > hp > > > -- Angular momentum makes the world go 'round.