gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

91 行
8.1KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>25.2. File System Level Backup</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="backup-dump.html" title="25.1. SQL Dump" /><link rel="next" href="continuous-archiving.html" title="25.3. Continuous Archiving and Point-in-Time Recovery (PITR)" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">25.2. File System Level Backup</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="backup-dump.html" title="25.1. SQL Dump">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="backup.html" title="Chapter 25. Backup and Restore">Up</a></td><th width="60%" align="center">Chapter 25. Backup and Restore</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="continuous-archiving.html" title="25.3. Continuous Archiving and Point-in-Time Recovery (PITR)">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="BACKUP-FILE"><div class="titlepage"><div><div><h2 class="title" style="clear: both">25.2. File System Level Backup</h2></div></div></div><p>
  3. An alternative backup strategy is to directly copy the files that
  4. <span class="productname">PostgreSQL</span> uses to store the data in the database;
  5. <a class="xref" href="creating-cluster.html" title="18.2. Creating a Database Cluster">Section 18.2</a> explains where these files
  6. are located. You can use whatever method you prefer
  7. for doing file system backups; for example:
  8. </p><pre class="programlisting">
  9. tar -cf backup.tar /usr/local/pgsql/data
  10. </pre><p>
  11. </p><p>
  12. There are two restrictions, however, which make this method
  13. impractical, or at least inferior to the <span class="application">pg_dump</span>
  14. method:
  15. </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>
  16. The database server <span class="emphasis"><em>must</em></span> be shut down in order to
  17. get a usable backup. Half-way measures such as disallowing all
  18. connections will <span class="emphasis"><em>not</em></span> work
  19. (in part because <code class="command">tar</code> and similar tools do not take
  20. an atomic snapshot of the state of the file system,
  21. but also because of internal buffering within the server).
  22. Information about stopping the server can be found in
  23. <a class="xref" href="server-shutdown.html" title="18.5. Shutting Down the Server">Section 18.5</a>. Needless to say, you
  24. also need to shut down the server before restoring the data.
  25. </p></li><li class="listitem"><p>
  26. If you have dug into the details of the file system layout of the
  27. database, you might be tempted to try to back up or restore only certain
  28. individual tables or databases from their respective files or
  29. directories. This will <span class="emphasis"><em>not</em></span> work because the
  30. information contained in these files is not usable without
  31. the commit log files,
  32. <code class="filename">pg_xact/*</code>, which contain the commit status of
  33. all transactions. A table file is only usable with this
  34. information. Of course it is also impossible to restore only a
  35. table and the associated <code class="filename">pg_xact</code> data
  36. because that would render all other tables in the database
  37. cluster useless. So file system backups only work for complete
  38. backup and restoration of an entire database cluster.
  39. </p></li></ol></div><p>
  40. </p><p>
  41. An alternative file-system backup approach is to make a
  42. <span class="quote">“<span class="quote">consistent snapshot</span>”</span> of the data directory, if the
  43. file system supports that functionality (and you are willing to
  44. trust that it is implemented correctly). The typical procedure is
  45. to make a <span class="quote">“<span class="quote">frozen snapshot</span>”</span> of the volume containing the
  46. database, then copy the whole data directory (not just parts, see
  47. above) from the snapshot to a backup device, then release the frozen
  48. snapshot. This will work even while the database server is running.
  49. However, a backup created in this way saves
  50. the database files in a state as if the database server was not
  51. properly shut down; therefore, when you start the database server
  52. on the backed-up data, it will think the previous server instance
  53. crashed and will replay the WAL log. This is not a problem; just
  54. be aware of it (and be sure to include the WAL files in your backup).
  55. You can perform a <code class="command">CHECKPOINT</code> before taking the
  56. snapshot to reduce recovery time.
  57. </p><p>
  58. If your database is spread across multiple file systems, there might not
  59. be any way to obtain exactly-simultaneous frozen snapshots of all
  60. the volumes. For example, if your data files and WAL log are on different
  61. disks, or if tablespaces are on different file systems, it might
  62. not be possible to use snapshot backup because the snapshots
  63. <span class="emphasis"><em>must</em></span> be simultaneous.
  64. Read your file system documentation very carefully before trusting
  65. the consistent-snapshot technique in such situations.
  66. </p><p>
  67. If simultaneous snapshots are not possible, one option is to shut down
  68. the database server long enough to establish all the frozen snapshots.
  69. Another option is to perform a continuous archiving base backup (<a class="xref" href="continuous-archiving.html#BACKUP-BASE-BACKUP" title="25.3.2. Making a Base Backup">Section 25.3.2</a>) because such backups are immune to file
  70. system changes during the backup. This requires enabling continuous
  71. archiving just during the backup process; restore is done using
  72. continuous archive recovery (<a class="xref" href="continuous-archiving.html#BACKUP-PITR-RECOVERY" title="25.3.4. Recovering Using a Continuous Archive Backup">Section 25.3.4</a>).
  73. </p><p>
  74. Another option is to use <span class="application">rsync</span> to perform a file
  75. system backup. This is done by first running <span class="application">rsync</span>
  76. while the database server is running, then shutting down the database
  77. server long enough to do an <code class="command">rsync --checksum</code>.
  78. (<code class="option">--checksum</code> is necessary because <code class="command">rsync</code> only
  79. has file modification-time granularity of one second.) The
  80. second <span class="application">rsync</span> will be quicker than the first,
  81. because it has relatively little data to transfer, and the end result
  82. will be consistent because the server was down. This method
  83. allows a file system backup to be performed with minimal downtime.
  84. </p><p>
  85. Note that a file system backup will typically be larger
  86. than an SQL dump. (<span class="application">pg_dump</span> does not need to dump
  87. the contents of indexes for example, just the commands to recreate
  88. them.) However, taking a file system backup might be faster.
  89. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="backup-dump.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="backup.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="continuous-archiving.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">25.1. <acronym class="acronym">SQL</acronym> Dump </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 25.3. Continuous Archiving and Point-in-Time Recovery (PITR)</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1