Jason Adams's picture

Greetings,

I'm using Pg 9.1 on the most recent LAPP TK. This is deployed via OpenVZ on a Proxmox server.

This will be given, along with other equipment, to a client. What I'm really curious of is ways of backing up the Pg database I can suggest/offer them, aside from TKLBAM — I don't want to use this because it needs to work on a closed network. The trick is, I'm fairly new to Linux and still associating myself it. I'm now trying to trudge into the area of creating local/remote backups on Linux systems, and especially how to do it in a scheduled form.

I could write a console app that connects to a machine elsewhere and handles the backups... but I feel like I'm re-inventing the wheel. Any and all suggestions are appreciated.

Thanks! Loving Turnkey! :)

Forum: 
Tags: 
Jeremy Davis's picture

But I'd imagine that there is a command to dump the database. You could then rsync or sftp the dump to wherever you wish to store it. 

There may be something already, but creating a script yourself should be fairly trivial. Create a basic script to do the above 2 steps and run it from cron (setting whatever schedule you want - hourly, daily, etc). I also suggest that you set it to log somewhere too. That should also be pretty easy, when you set up the cron job, send the output to a file (instead of the screen).

Jason Adams's picture

Thanks, man! You're correct in that it has a pg_dump function, and I'm familiar with how to properly dump and store the db. Unfortunately I have no experience with writing Linux scripts, but I'm looking into tutorials and the like now.

If you have any suggestions on good resources, please let me know.

Jeremy Davis's picture

So basically if you take note of commands you use to achieve your ends, put then in a plain text file (NOT a Windows text file though...!) Put "#!/bin/bash" on the first line (so Linux knows it's a script). So it'd look something like this:

#!/bin/bash
<pg-dump command>
<rsync/ftp command to copy to desired backup location>
#end

Then make it executable:

chmod +x <filename>

And test it:

./path/to/filename

When you set it up to run as a cron job, just remember that you will need to put the full path to the script.

Google is a great resource for working out the details of bash scripts (and most things Linux). For scripting use keywords like "bash", "linux", debian", "commandline" etc.

Add new comment