Now that we're able to get the database information from our remote server, we're ready to implement the two backup methods that we need. To start, we'll add the local storage functionality.
pgbackup.dump method is returning
subprocess.Popen and that object has a
stdout attribute that acts like a file. We also want to write the contents of the backup to a file, so we can write a function that assumes it will receive two open files and transfers the contents from one file to another. Let's add all of the code related to storing the backup into a new file called
By limiting our scope in that way, we can write a fairly simple function that creates the local backup. Here's what we plan to do:
infileand write them to the
We want to call
close on the "writeable" file to ensure that all of the content gets written (the database backup could be quite large).
def local(infile, outfile): outfile.write(infile.read()) outfile.close() infile.close()