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 1mqIFG-0007bW-9o for pgsql-performance@arkaria.postgresql.org; Thu, 25 Nov 2021 17:09:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mqIFE-0000Jv-MJ for pgsql-performance@arkaria.postgresql.org; Thu, 25 Nov 2021 17:09:12 +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 1mqIFE-0000Jl-7Q for pgsql-performance@lists.postgresql.org; Thu, 25 Nov 2021 17:09:12 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mqIF9-0004zw-9F for pgsql-performance@postgresql.org; Thu, 25 Nov 2021 17:09:11 +0000 Received: by mail-oi1-x233.google.com with SMTP id be32so13703392oib.11 for ; Thu, 25 Nov 2021 09:09:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=5qDJlMt8jsV7QhwwdT5IshnBhb8s4+BV5fB5rt9baF0=; b=6X6aJtg38D4EXtbpwgv1CeN554AsUFpuLTvvUXUFkxBGu/pfSI1OzIFl/bEQlgPG2b G4EHDIzMMYBN1dBJXh48hL5FGLdJPHmihMtiyR+QugiOtrGpYm6pCr51mSd+HnZwf5mv q85Dcuuni9/6B06bu4M0bCpdYuiq11eCXUxGwRqTC2RUSfDxVIjMLfcZR2DMd9b7+2UU r/7mlQdzxmJrwX41OyzaDf/wNA8yXEPGzaYY9MRsWdskT6m4MKOe3vR2gCvWKDb0SRCD ld+SUtEbV/KV8V1CAnA6q+US+vre4MWwgcfNmQRFGXyTD42EAMg+/4SeKrcb5JfG4tFz UNYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=5qDJlMt8jsV7QhwwdT5IshnBhb8s4+BV5fB5rt9baF0=; b=aW2vy6bwh5wAs0EdzUKuL3UXMebAjmZpLCIPqzPO5XMadDNT35vQ49p7QhqSXufFKw JpDXi+i83BP8mS1GzF+jP9qgqPURjlNlDKeeW7sNRlkaNtk0yookw5dvS0rOAWS+JYg4 DSm50pCzL+uREmoYrPGRXBhFwPkHPJu6fnyRdFM6ZRcxmLK7/tetGjiQrTbRnfBnkn45 87Co9nePzKdsaOAKTkuJZF2LSe36CzPvVji2bTJjKFnybjPvdDIU55GQDtJmUgMgCXhp f2Xgg16KTAzhWckXWLAVWJjU4+gqqdPX7eJ4N88SS39QKDpWG1HtAIzUUdfmhzJ+7nkB u6rg== X-Gm-Message-State: AOAM532BVdfkmD3X0jBnCoPsh7fqAtiDyheZXu1IMqFzZ8GcsS/zk1dM vvGkNB4tbXHFc56IuW/laCruDBzuhvkr7g== X-Google-Smtp-Source: ABdhPJzd4Ru5F8VpdubcMg2bN2oB06GHJhX+AMzygM2/4P3yJRORuczhwS9dMMeV1CUwK2QgMhbzqA== X-Received: by 2002:a05:6808:f01:: with SMTP id m1mr17533415oiw.166.1637860145007; Thu, 25 Nov 2021 09:09:05 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id q1sm727472oiv.42.2021.11.25.09.09.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Nov 2021 09:09:04 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id A65F2801B2C; Thu, 25 Nov 2021 11:09:03 -0600 (CST) Date: Thu, 25 Nov 2021 11:09:03 -0600 From: Justin Pryzby To: Daulat Cc: pgsql-performance@postgresql.org Subject: Re: pg_dump backup verification Message-ID: <20211125170903.GD17618@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Nov 25, 2021 at 02:41:34PM +0530, Daulat wrote: > Please suggest how I can ensure pg_dump backup has completed successfully ? > I don't think there is any view like Oracle which helps with > dba_datampump_jobs etc. 1) Check its exit status. If it's nonzero, then surely there's a problem (typically detailed indicated by output to stderr). 2) You can also run pg_restore -l to output a TOC for the backup. From experience, this can be a good secondary test. You could add to your backup script "pg_restore -l ./thebackup >/dev/null" to check that pg_restore itself exits with a zero exit status. 3) If your backup job is a shell script, you should use "set -e", to be sure that a command which fails causes the script to exit rather than plowing ahead as if it had succeeded. This is important for any shell script that's more than 1 line long. 4) It's usually a good idea to write first to a "*.new" file, and then rename it only if the pg_dump succeeds. Avoid "clobbering" a pre-existing file (or else you have no backup at all until the backup finishes, successfully). Avoid piping pg_dump to another command, since pipes only preserve the exit status of the final command in the pipeline. For example: #! /bin/sh set -e f=/srv/otherfs/thebackup rm -f "$f.new" # Remove a previous, failed backup, if any pg_dump -Fc -d ourdatabase >"$f.new" pg_restore -l "$f.new" >/dev/null mv "$f.new" "$f" exit 0 # In case the previous line is a conditional like "if" or "&&" or "||". 5) You can monitor the age of ./thebackup. 6) Log the output of the script; do not let its output get redirected to /var/mail/postgres, or somewhere else nobody looks at. 7) It's nice to dump to a separate filesystem; not only because FS corruption would affect both the live DB but also its backup. But also because the backups could overflow the FS, causing the main DB to fail queries or crash. 8) Keep a few backups rotated weekly and a few rotated monthly. Even if it's never needed to restore a 2 month old backup, it can be valuable to help diagnose issues to see when some data changed. 9) Also save output from pg_dumpall -g, or else your backup will probably spew out lots of errors, which are themselves important, but might also obscure other, even more important problems. 10) Perhaps most importantly, test your backups. Having backups is of little use if you don't know how to restore them. This should be a periodic procedure, not something you do once to be able to say that you did. Are you confident you can run using the restored DB ? -- Justin