# Back up the database, scheduled to be run nightly. As written, it # keeps a month's worth of daily backups, cycling over the same files # which are suffixed with the day of the month on which the backup is # created. # Original version by Don Baccus (dhogaza@pacifier.com> # Modified for openacs4 by Vinod Kurup # 18 Jan 2002 # This version: ftp only. proc acs_pgbackup {} { # Set these to the appropriate values for your installation. set pg_bin "/usr/local/pgsql/bin" set bak "/usr/local/aolserver/backup" set servername "birdnotes" set ftp_user "my-ftp-username" set ftp_password "my-ftp-password" set ftp_dir "my-ftp-path" set ftp_server "my.ftpserver.com" set day [clock format [clock seconds] -format %d] set data "${servername}_${day}.dmp" ns_log Notice "Backup of [ad_system_name] starting." ns_log Notice "pg_dump beginning..." if [catch {append msg [exec "$pg_bin/pg_dump" $servername ">$bak/$data"]} errmsg] { ns_log Error "pg_dump failed: $errmsg" ns_sendmail [ad_system_owner] [ad_system_owner] "[ad_system_name] : pg_dump failed..." "$errmsg" return } append msg "\n" ns_log Notice "gzip of data beginning..." if [catch {append msg [exec "gzip" "-f" "$bak/$data"]} errmsg] { ns_log Error "gzip of data failed: $errmsg" ns_sendmail [ad_system_owner] [ad_system_owner] "[ad_system_name] : gzip of data failed..." "$errmsg" return } append msg "\n" ns_log Notice "ftp data beginning..." set fd [open "$bak/ftp_data.tmp" w] puts $fd "user $ftp_user ${ftp_password}\nbinary\nput $bak/$data.gz ${ftp_dir}/$data.gz\nquit\n" close $fd if [catch {append msg [exec "ftp" "-n" $ftp_server "<$bak/ftp_data.tmp"]} errmsg] { ns_log Error "ftp data failed: $errmsg" ns_sendmail [ad_system_owner] [ad_system_owner] "[ad_system_name] : ftp data failed..." "$errmsg" return } append msg "\n" # Replicate the above code to make remote copies to other systems ns_log Notice "vacuum beginning..." if [catch {append msg [exec "$pg_bin/vacuumdb" "-q" "-z" "$servername"]} errmsg] { ns_log Error "vacuum failed: $errmsg" ns_sendmail [ad_system_owner] [ad_system_owner] "[ad_system_name] : vacuum failed..." "$errmsg" } ns_log Notice "Backup succeeded." append msg "Backups succeeded" ns_sendmail [ad_system_owner] [ad_system_owner] "[ad_system_name] : backup succeeded" "$msg" } if { ! [nsv_exists acs_pgbackup scheduled_p] } { ns_schedule_daily 0 0 acs_pgbackup nsv_set acs_pgbackup scheduled_p 1 ns_log Notice "Backup has been scheduled." }