Recent

Author Topic: How can I save database current state as file?  (Read 1725 times)

loaded

  • Hero Member
  • *****
  • Posts: 825
How can I save database current state as file?
« on: October 11, 2021, 10:09:00 am »
Hi All,
The database I use is Postgresql, I use Pgadmin for backup and restore operations.
My aim is; Can I save the state of the DATASOURCEI use when I make a SQL query to the file? And then can I update the database by posting this file?
It could be: To take a backup of the table I use, together with the schema and data, as a binary file via LAZARUS, and to restore it using this file when necessary.
Is it possible ?
If anyone has any experience with the subject, I'd appreciate it. Respects.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: How can I save database current state as file?
« Reply #1 on: October 11, 2021, 11:05:20 am »
I'd suggest using the dump/restore facilities provided by PostgreSQL. You're unlikely to improve on the performance, and they're using subtlety that you won't necessarily get on a generic API to do the job thoroughly. Something like

Code: Bash  [Select][+][-]
  1. #! /bin/bash
  2.  
  3. # Note that the dump always generates a file named for the local machine. That
  4. # way even if the customised backup.ftp gets copied to the wrong system files
  5. # won't overwrite each other. MarkMLl.
  6.  
  7. export HOSTNAME=`/bin/hostname`
  8.  
  9. export DUMP_OPTIONS='--clean --oids'
  10. export COPY_TARGET=/export/pgsql-backup
  11.  
  12. # The environment may be empty if this is in crontab.
  13.  
  14. export PATH=/usr/bin:/bin
  15. export HOME=/var/lib/postgresql
  16.  
  17. # Generate the backup and copy to the target.
  18.  
  19. pg_dumpall $DUMP_OPTIONS 2>/var/log/pgsql-backup | /bin/gzip >$HOME/$HOSTNAME.gz
  20.  

MarkMLl
« Last Edit: October 11, 2021, 12:53:36 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Thaddy

  • Hero Member
  • *****
  • Posts: 14385
  • Sensorship about opinions does not belong here.
Re: How can I save database current state as file?
« Reply #2 on: October 11, 2021, 12:16:49 pm »
Mark, You can at least write "
Code: Bash  [Select][+][-]
  1. "
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

loaded

  • Hero Member
  • *****
  • Posts: 825
Re: How can I save database current state as file?
« Reply #3 on: October 11, 2021, 12:31:00 pm »
MarkMLl and Thaddy thank you very much for the reply.
Also, thank you for sharing your experience. This experience is also very valuable to me.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: How can I save database current state as file?
« Reply #4 on: October 11, 2021, 12:53:12 pm »
Mark, You can at least write "
Code: Bash  [Select][+][-]
  1. "

Ah, I was about to ask for explanation since that didn't show up properly... you could at least have used the markup that prevents markup from marking up. Whatever it is.

I admit that I don't always remember that some people consider shell scripting to be a language and that it's handled by SMF :-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018