source: tcl/backup.tcl @ 1

Last change on this file since 1 was 1, checked in by mek, 8 years ago

initial import

File size: 2.0 KB
Line 
1### Backup Script, pretty much the one Don Baccus include in his OpenACS docs
2### I have just added a backup of all files, except the backup directory
3proc backup {} {       
4    set server "turl"
5    set b "/usr/bin" 
6    set d "/web/${server}"
7    set bak "${d}/backup"         
8    set tar "/bin/tar"
9    set db [ns_db gethandle] 
10    set sql "select date_part('day','today'::date) as day" 
11    set selection [ns_db 1row $db $sql] 
12    set_variables_after_query
13    set data "${server}_$day.dmp"
14    set backup "${server}_$day.tar.gz" 
15    ns_log Notice "Backup of [${server}_system_name] starting."
16    ns_log Notice "pg_dump beginning..."       
17    if [catch {append msg [exec "$b/pg_dump" "${server}" ">$bak/$data"]} errmsg] { 
18        ns_log Error "pg_dump failed: $errmsg" 
19        ns_sendmail [${server}_system_owner] [${server}_system_owner] "[${server}_system_name] : pg_dump failed..." "$errmsg" 
20        ns_db releasehandle $db 
21        return
22    }     
23    append msg "\n"
24    ns_log Notice "gzip of data beginning..."   
25    if [catch {append msg [exec "gzip" "-f" "$bak/$data"]} errmsg] { 
26        ns_log Error "gzip of data failed: $errmsg" 
27        ns_sendmail [${server}_system_owner] [${server}_system_owner] "[${server}_system_name] : gzip of data failed..." "$errmsg" 
28        ns_db releasehandle $db 
29        return
30    }   
31    append msg "\n"
32
33    ns_log Notice "Backup for filesystem started"
34    if [catch {append msg [exec  "$tar" "-cPz" "--exclude=$bak/*" "--file" "$bak/$backup" "$d"]} errmsg] {
35        ns_log Error "backup for files filed: $errmsg"
36        ns_sendmail [${server}_system_owner] [${server}_system_owner] "[${server}_system_name] : backup for files failed..." "$errmsg" 
37        ns_db releasehandle $db
38        return
39    }
40    append msg "\n"
41 
42    ns_log Notice "Backup succeeded." 
43    append msg "Backups succeeded"
44    ns_sendmail [${server}_system_owner] [${server}_system_owner] "[${server}_system_name] : backup succeeded" "$msg" 
45}       
46
47ns_share -init {set schedule_backup 0} schedule_backup
48if {!$schedule_backup} { 
49    ns_schedule_daily 0 0 backup
50    ns_log Notice "Backup has been scheduled." 
51}
Note: See TracBrowser for help on using the repository browser.