How to backup and restore postgres, How to backup and restore postgres

Hi!
Yesterday I had a major hickup while trying to configure some OD stuff. Since I was still setting up Lion Server, I just decided to go back and restore the system using a Time Machine backup from a few hours earlier. Went well... except that anything to do with postgres was not working anymore: web pages, wiki, iCal, etc Postgres would not start anymore. I could not find anything on the internet and after a few hours of trying gave up and just did a fresh, clean install. Fortunately there were not many user files on yet, but I did lose everything I noted in the wiki since I migrated the old Snow Leopard content.
SO, HERE comes the question: is there a fool-proof way of backing up all Lion Server postgres databases and, more importantly, to actually get the thing back up after a Time Machine restore? I know I can dump all db's using pg_dumpall, but what would be the steps to get this back up and running should I need to? I have restored many MySQL databases in the past, but never were they directly linked to many OS functionalities.
The "Advanced Administration" document of course is not advanced enough for this. Is there anywhere I real guide on "How to restore and make function your Lion Server after a major desaster", like hard disk failure?? Would be very helpful, in case it's needed but also for peace of mind.
Thanks lot! Appreciate any input!
Cheers,
Hendrik

Take my little script here and adjust it to your requirements. I got the base of this script somwhere else and enhanced it myself. Read some explanations below:
# #!/bin/bash
if (test "`whoami`" != "root") then
        echo "You need to be root to start this"
        exit 1
fi
PG_PORT="5432"
PG_USER="_postgres"
PG_BIN="/usr/bin/"
ACT_DATE=$(date '+%y-%m-%d')
EXP_DATE=$(date -v -2w '+%y-%m-%d')
BACKUP_DIR="/Backups/postgres"
LOGFILE=$BACKUP_DIR"/_pg_backup.log"
COMPRESSION="9"
PG_CON="-U $PG_USER"
BACKUP_OPTIONS="$PG_CON -b -C -F c -Z $COMPRESSION"
VACUUM_OPTIONS="$PG_CON -eq"
echo "***** DB_BACKUP $ACT_DATE *****" >>$LOGFILE
for db in `$PG_BIN/psql $PG_CON -lt | sed /\eof/p | grep -v = | awk {'print $1'}`
  do
    # vacuum
    if [ "X" == "X$db" ]; then
          continue;
    fi
    echo $(date '+%c')" -- vacuuming database $db" >> $LOGFILE
    if $PG_BIN/vacuumdb $VACUUM_OPTIONS $db
      then
      #echo "OK!" >>$LOGFILE
          sleep 1
    else
      echo "No Vacuum in database $db!" >>$LOGFILE
    fi
    # backup
    echo $(date '+%c')" -- backing up database $db" >>$LOGFILE
    if  $PG_BIN/pg_dump $BACKUP_OPTIONS -f $BACKUP_DIR/$db-$ACT_DATE.pgdump $db
      then
      if [ -e $BACKUP_DIR/$db-$EXP_DATE.pgdump ]; then
          echo $(date '+%c')" -- deleting old backup" >>$LOGFILE
          rm $BACKUP_DIR/$db-$EXP_DATE.pgdump
      fi
    else
      echo "FAIL Database $db backup!" >>$LOGFILE
    fi
  done
This script dumps all databases in postgres individually.
Databases are vacuumed and then dumped.
Dump-Format is currently set as compressed pgsql dump (See "-F c" in $BACKUP_OPTIONS)
File names consist of "databasename"-"backupdade".pgdump
I have programmed to automatically purge backups older than two weeks (see " -2w " in $EXP_DATE)
If you drop a database you will have to remove backups for that database manually.
I have enabled a daily run of this scrip by placing the executable script somwhere and add it to the crontab of root: sudo crontab -e
Enter the following line and your backups start every day at 6:00. Adjust paths and scriptname according to your own setup.
0 6 * * *       ~/.bin/postgres_dump.sh > /dev/null 2>&1

Similar Messages

  • I backup my iphone on my pc and copy backup file into drive D then i setup new OS on my pc. after that i copy the backup file into itunes backup folder but itunes can't find the backup file to restore my iphone. how can i restore my iphone?

    i backup my iphone on my pc and copy backup file into drive D then i setup new OS on my pc. after that i copy the backup file into itunes backup folder but itunes can't find the backup file to restore my iphone. how can i restore my iphone?

    Don't you just love changes in interfaces?
    I found the answer to my question.
    When you attach a device (iPhone, iPad) to your Mac, in iTunes 12 in appears as a tiny icon in the second "row" of the iTunes display. Click the icon and the familiar iTunes display for the device appears. From there, on the Summary screen, you can see the dates of the backups of the device (iCloud and backup to the computer). You can also use the button to backup to the computer.

  • How do i use the recovery disks and backup and restore my laptop in a new HDD without losing OS lic?

    I am running a HP-DV6 6090ee laptop with windows 7 Home Premium 64bit OS. This problem started from last evening.
    I am getting a "Smart Hard disc error" error message before boot and ater booting windows saying that my HDD is having problems and i need to backup and check the hdd.
    After checking i found that i have a corrupted hdd and i am going to replace with a new one.
    I need to know the following :
    > How do i restore my windows license and my antivirus license in the new hdd?
    > i dont currently have a OEM HP OS cd. can i use any windows 7 cd??
    > at what stage should i use the recovery disk i created from the recovery partition be used? Whats its specific use?
    I really appreciate any quick response as my current HDD is running out of life.
    Regards
    A

    See these 2 Links...
    Syncing to a New Computer...
    https://discussions.apple.com/docs/DOC-3141
    Recovering your iTunes library from your iPod or iOS device
    https://discussions.apple.com/docs/DOC-3991

  • My icloud backup paused on my iPhone 5S and i can't get it to finish.  how do I get to to complete the restore process?

    When I got home from the store, I had to retrieve my backup from and Iphone 5.  It restored most things, but it has not finished.  It promoted me to connect to itunes, but that hasn't helped either.  I need it to finish restoring so that I can back it up. Any ideas?
    Thanks,

    It was O2 he was on. I don't know if it was unlocked. How do I check? And also how would I get it unlocked?

  • How can I restore my data from iCal? I didn't make any backup, but I use  time machine with an external HD. I deleted iCal when I deleted my gmail account. I have tried to restore, but I can only restore the iCal software and not the data.

    How can I restore my data from iCal? I didn't make any backup, but I use  time machine with an external HD. I deleted iCal when I deleted my gmail account. I have tried to restore, but I can only restore the iCal software and not the data.

    So what is your question?
    If you forgot your encryption password:
    Warning: Make sure it's a password you will remember or write it down for safekeeping. If you encrypt an iPhone backup in iTunes and forget your password, you can't restore from backup and your data will be unrecoverable.
    If you can't remember the password and want to start again, you must perform a full software restore and chooseset up as a new device when iTunes prompts you to select the backup from which to restore.
    The above comes from here:
    http://support.apple.com/kb/HT4946

  • Trying to rebuild my iphoto library from time machine backup and it still says 0 restored with a grey screen and the circle. How can i restore my library?

    I just bought a new Macbook pro and i tried to rebuild my iphoto library from a time machine backup on an external hard drive. Even after pressing command+option when starting iphoto and selecting rebuild library from automatic backup, it still doesn't work with the grey screen with the white circle and a little window that says 'rebuilding library: 0 versions restored'. I also tried to make a copy of my iphoto library but that did not work either. how can i restore my iphoto library or at least gain access to my photos?

    Your question is not clear
    Rerairing or rebuilding the iPhoto library never involves using Time Machine in any way
    TM is a totally seperate program and you can "restore" a file (including the iPhoto library) from the past using TM - you launch TM and go back to the time you want and select the file (or folder or package) you want and click restore - it probably is best to keep the current one until you are sure everything is good
    LN

  • Iphone4 would not restore Error -50. I have tried to restore and it restored it to the point that it created after 5.0 was installed. How can I get it an older restore point from my backups and restore it on another computer? The phone has been wiped out.

    Iphone would not restore---- Error -50. I have tried to restore, and it restored it to the new point that it created after 5.0 was installed. How can I get it an older restore point from my backups and restore it on another computer? The phone has been wiped out. I can see earlier backups in my C:\Documents and Settings\user\Application Data\Apple Computer\MobileSync\Backup folder. There are four subfolders in this address. I need my contacts, photos, and messages back. I know this is a common error but I can not figure it out. I have ran the other troublshoot items in the error steps for 13 and 14 like apple says. Is there a way to call apple and get a step by step of how to restore from another restore point? Does anybody have a solution????

    It tells you to go to Error 13 and 14 if you receive error (-50).
    Here is what I have tried...
    Error 13 and 14: These errors are typically resolved by performing one or more of the steps listed below:
    Perform USB isolation troubleshooting, including trying a different USB port directly on the computer. See the advanced steps below for USB troubleshooting. I have moved it around to different ports.
    Put a USB 2.0 hub between the device and the computer. Didn't change anything.
    Try a different USB 30-pin dock-connector cable.
    Eliminate third-party security software conflicts. Removed all virus protection and firewall.
    There may be third-party software installed that modifies your default packet size in Windows by inserting one or more TcpWindowSize entries into your registry. Your default packet size being set incorrectly can cause this error. Contact the manufacturer of the software that installed the packet-size modification for assistance. Or, follow this article by Microsoft: How to reset Internet Protocol (TCP/IP) to reset the packet size back to the default for Windows.Used the Microsoft fix it.
    Connect your computer directly to your Internet source, bypassing any routers, hubs, or switches. You may need to restart your computer and modem to get online. Doesn't matter.
    Try to restore from another known-good computer and network. I do not know how to do this or how to find the correct/full/complete restore point. There should be more information for this.

  • How do i backup my iphone 3 started on one itunes account and restore to the same phone with a different itunes account without losing all my information?

    how do i backup my iphone 3 started on one itunes account and restore to the same phone with a different itunes account without losing all my information?

    Please search the forums. This has been covered here extensively.

  • How can I email my iPhone backup from one computer to another?  And then how do I restore my iPhone to this backup once it's on the new computer?

    I updated my iPhone onto my friend's MacBook, but then I lost that iPhone.  When I plugged in a different iPhone to his computer, it did ask me if I wanted to restore it as my old phone, so I must have backed up at least some of the data to his iTunes.  I saw that you can locate the folder where my iPhone was backed up, so can he just email me the folder (he lives in a different country)?  And then if I get this folder, how do I then put all that data back into my current phone from the new computer?

    I updated my iPhone onto my friend's MacBook
    Why would you do that, and not on your own computer?  See the hassle it caused you?
    can he just email me the folder
    Backup files are too big to email.  Use FTP, DropBox, etc...
    how do I then put all that data back into my current phone from the new computer?
    How to restore iPhone:  http://lmgtfy.com/?q=how+to+restore+iphone

  • How do I locate an iCal calendar from a backup and restore?

    I need help in restoring a calendar that I deleted. I haven't used Time Machine since May, but I do use SuperDuper and have a clone of my hard drive backed up through yesterday. I am pretty sure the file is there somewhere, I just don't know where or how to get it back into iCal.
    Here is what happened...
    *I use Mobile Me to sync my iMac (primary), MacBook and iPhone.*
    A week ago I was trying to get my "Sports" calendar subscribed to my daughters old iMac. After reading the forums, the suggestions were to rename the calendar and try again, which I did. Changed it to "Kids Sports" and it seemed to allow her to subscribe, although updates/additions/deletions never made it to her computer. I left it alone at that point, knowing it still wasn't working properly but she had the brunt of her schedule.
    Then sometime in the last few days I downloaded a schedule for my child's soccer tournament using my MacBook. It placed 3 games (with all the times, locations, etc) onto my MacBook, I thought wow, how cool, I didn't have to type all the info myself. I have never downloaded a calendar file before.
    I noticed a little while later that those 3 games did not sync to my phone or iMac. I investigated and thought the time zone may have been the culprit, I can't remember what was listed but it wasn't a time zone, it was something like "undetermined" or along those lines (can't see it now because the calendar is gone), so I changed each of those 3 events to Central Time manually. Later they show up as 5 hours earlier than Central Time.
    Yesterday I open up iCal in the MacBook and it's showing my "Personal" calendar with thousands of duplicate entries that are selected to "never" end, going back to around the year 2000. I have no idea how my "personal" calendar got this way, I haven't changed anything with it. Since I've been working on the "sports" calendar mess. I deleted the events in the "personal" calendar from October 1st going forward, of course everything prior to that is still there. About 4 events listed for everyday and to never end.
    I also get a message that I have over 2200 entries that need to be reviewed in iCal before syncing last night. It's the calendar labeled "kids sports". I can see that in iCal I now have 2 sports calendars, "sports" and "kids sports", they both seem to have the same information in them, so I sync with the "kids sports" calendar to be deleted. WRONG answer! All that is left are the 3 events from the calendar I downloaded online, in the calendar labeled "sports".
    Everything is already deleted from MobileMe as well.
    Soooo, is it possible to pull the "kids sports" file from somewhere in the applications area and put it back where it belongs from my back up?
    It seems like once a year I have a major issue with MobileMe duplicating, but I have yet to understand what I am doing wrong!
    Thanks,
    Sandy

    Anyone?
    Let us get home from work first
    I see my daughter's old iMac still has the "kids sports" calendar showing up with all the info still showing on her iCal, but she is subscribed to that calender versus syncing with it. I'm not sure if she has it set to manually refresh or automatically refresh.
    If the calendar shows up fine on her computer the easiest way to get it cleanly is to get it from her computer if that is your goal. I'm assuming this is a calendar you created on your computer and then published and then she subscribed to it?
    _Go to her computer.
    _Click on the calendar in question on the left hand side once.
    _Go to File > Export > Export and save to the desktop.
    _Bring the resulting .ics file to your computer.
    _Delete the current kids sports calendar from your computer.
    _Double-click the .ics file your brought over and add it to a "New Calendar"
    _Now you can re-publish that calendar.
    I don't understand why I can't use Superduper! to find the deleted calendar (deleted today and sync'd)
    I'm afraid I've never used Superduper! so I can't offer any suggestion there. You may want to ask the maker of that software how to restore from their backups. I use Time Machine. However if SuperDuper! clones your hard drive as you say then all your calendars are stored in Your User > Library > Calendars on that backup.
    You don't restore individual Calendars with iCal because it is one large database (in truth you can but it is very time consuming as every single event has it's own individual .ics file). So when you want your calendar from a certain restore point in time (when you made the last backup) you can follow these steps:
    _Quit iCal completely
    _Go to Macintosh HD > Applications > iSync
    _Open iSync
    _Go to iSync > Preferences and remove the check mark for "Enable syncing on this computer"
    _Reset Sync Services: http://support.apple.com/kb/TS1627
    _Remove Your User > Library > Calendars to the Trash
    _Copy the Calendars folder from your backup and put it in Your User > Library where the old one used to be
    _Launch iCal and check for your calendars
    _If the calendars show up ok go back to iSync and re-check the box for "Enable syncing on this computer"
    Hope that helps.

  • Have to update my iPad 2 iOS and don't know how to backup or sync photos and music, videos etc, to my windows 7 laptop. Then Iknow I need to update to iOS 5 before I can restore apps, and media, etc. Please help me, as I am not computer savvy.

    I need help on how to back up my  iPad 2  or sync my photos, videos, and music to my windows 7 laptop, b4 I can upgrade my iOS to ios5 and restore my appss and files, simple instructions please as I am not  computer knowledgeable, thanks for any help!

    When connecting ipad to itunes, in the Summary tab (in itunes for your device), look in the Backups section and choose to back up to itunes.
    Read this...  import photos to your computer...
    http://support.apple.com/kb/HT4083

  • I have a new SIM/service and want to transfer all my contacts from the current 4S to the new SIM in my old 3GS.  I do NOT want to backup/restore the entire phone contents (iTunes or iCloud), JUST the contacts.  How?

    Current phone 4S with service from one provider.  Also have a new SIM with another provider, and want to copy my contacts from the 4S across to my old 3GS which I will be using for a bit as an alternative.  Definitely do not want anything except the contacts copied across so a full backup/restore is NOT what I'm after, and I can't see (in the iTunes backup) how to only do the contacts.

    Sorry, my bungle - from what devices I am used to - these Apple things still have me confused at times.
    The core requirement is the same - to get the contacts from the 4S onto the 3GS without backing up the whole device/apps etc.
    And a second part of that is how to get the contacts onto a SIM for a device that DOES store them there.  No doubt that will be a problem as it only has name/number combos, not all the fruit the iPhone keeps under a contact.  Maybe it can't done.  A simple export to CSV or something that could be edited would suffcie if there were an import tool to get it onto the SIM in the simpler format.

  • I have a clickfree backup drive and don't know how to restore my previous bookmarks? I tried to copy the places.sqlite file from the backup drive to my compute

    I have a clickfree backup drive and my computer crashed. I restored it to factory settings and reinstalled Firefox but cannot figure out how to get my old bookmarks back. I tried to replace the new places.sqlite file with the one I had on my backup drive but still got nothing? I tried to use the restore option but it won't take the old places.sqlite file. Is there anyway to get my old bookmarks? I'm really not a techy person.....
    Thanks

    Bookmark Backups
    Type '''about:support''' in the address bar and press enter.
    Under the page logo on the left side you will see '''Application Basics.'''
    Under this find '''Profile Folder.''' To it’s right press the button
    '''Show Folder.''' This will open your file browser to the current
    Firefox profile. Now '''Close Firefox.'''
    Enter the '''bookmarkbackups''' folder. This is where Firefox makes backups
    of your bookmarks. Look for the '''jsonlz4''' file you want to restore
    (check the time / date / size). Right click on that file and select '''Copy.'''
    Now go back to the profile folder where you started. Rename the file
    '''places.sqlite''' by adding '''.old''' to it. Now right click in the folder
    and select '''Paste.''' The file you just pasted here, rename it to
    '''places.sqlite.''' After you are done, restart Firefox.
    Edited to correct file name error.

  • Formatted HD, but have backup of all the folders and files of Firefox. How can I restore everything, including plugins, bookmarks and saved settings?

    I have formatted my computer's HD because of a problem with Windows 7, the thing is that Windows 7 didn't start, so I couldn't backup my Firefox settings, bookmarks, plugins, themes, personas and etc. the right way.
    I also don't have a Firefox Sync account.
    What I do have are all the folders and files of Firefox, because I just created a new partition and installed Windows 7 again, what I'm having trouble is finding a way (if there's any) to restore everything from my previous installation to the new one.
    I have searched for days on both Google and on te Firefox forum with no success, the only questions I found are about restoring a profile, but what I'm trying to do is the same thing that the Firefox add-on " FEBE " does, which is restoring everything to the previous configuration.
    Here's alink to the add-on: https://addons.mozilla.org/pt-br/firefox/addon/febe/
    I have tried copying, pasting and overwritting from the " .default " folder to my new installation of Firefox (yes, Firefox was closed), but when I opened it again, nothing was restored.
    I every single folder and file Firefox ever created on my computer, this includes the installation folder (at Program Files), the profile (.default at AppData) folder, the Mozilla folder (ProgramData) and the Mozilla Firefox folder (also at AppData).
    I also had the FEBE add-on installed, but like stated before, unfortunately I couldn't start Windows 7, forcing me to create a new partition to install a new copy of the OS.
    Thanks in advance.
    PS. Sorry if I made the text too long and/or if I mentioned the same things twice, just trying to be thorough.

    Hi Sdarts,
    I apologize for the delay in replying to your question, and I am sorry to hear that you are having issues restoring your Firefox user data.
    Please see the following article, which explains how to restore your Firefox user data using a previously backed up Profiles folder, which seems to apply to your situation:
    * [https://support.mozilla.org/en-US/kb/back-and-restore-information-firefox-profiles Backup and Restore information from Firefox Profiles]
    Please let us know if this solves your problem or if you have any questions.
    Thanks!!
    - Ralph

  • HT3576 How can I get rid of "Connect to itunes to use push notifications" pop-ups.  I just had to replace my iPhone 5 and when I did a restore from backup, most of my apps will not let me in becuase I cannot get past the"connect to itunes..." message.

    My iPhone 5 was distroyed so I replaced it with a new iPhone 5 yesterday.  I did a restore from a backup that i had performed a week ago.  When I tried to use the phone several of my apps would not let me in becuase they continually gave me a popup message "Connect to Itunes to use push notifications".  I click ok and the popup comes back.  I have shut my phone off several times.  I have complete closed the apps several times.  I have even deleted the apps from my phone and reinstalled.  All to no avail.  Please help - does anyone know how to fix this?

    Yes - I connected my phone to my computer / Itunes and went into the apps section, but from there I have no idea how to manage the push notifications.  I even tryied going into itunes that is installed on my phone.  I still cannot find anyplace to manage these popups.  I have also gone into settings - notifiations - and tried turning all notifications for these apps all off but that didnt work either.  Any guidance is MUCH appreciated - Im not sure where to go from here.

Maybe you are looking for

  • Need help to create a new record in mdm using java webdynpro

    hi all, I have to develop an application to create a new record in mdm by using java WebDynpro  . Please help me what is the process that i have to follow to do this and provide me if you have any step by step guidance for this. thanks & regards, Mah

  • Single invoice for multiple sales orders

    Hi all, When delivery order is created based on Collective processing, Billing document is created based on delivery order for delivery based billing. But, is it possible to filter the line items in the Collective delivery order further for billing?

  • JAXB: Creating Java content tree from scratch - examples?

    I'm trying to create XML output by building the content tree from scratch (using a the DDI schema which is fairly complex). I don't have any existing XML instances. Sample application 3 in Sun's JAXB tutorial doesn't give enough info about how to rel

  • Number of Songs

    Hey all, I have 2244 items in my "Music" playlist in iTunes. However, my iPod says I have 2243 songs. I do not have any "dead" songs, and all of my songs are in a format that will trnasfer to my iPod. I know this is relatively minor, but how can I fi

  • How can i control the DAQ directly from VB

    Actually, it is my first trial to use Visual Basic to get signal from DAQ. And i don't how to interface them. I have read an article to use DataSocket. However, it demostrated the OPC demo in OPC sever only, and so i didn't know how to get the signal