@@ -15,10 +15,11 @@ import (
15
15
/*
16
16
Data struct to configure dump behavior
17
17
18
- Out: Stream to wite to
19
- Connection: Database connection to dump
20
- IgnoreTables: Mark sensitive tables to ignore
21
- LockTables: Lock all tables for the duration of the dump
18
+ Out: Stream to wite to
19
+ Connection: Database connection to dump
20
+ IgnoreTables: Mark sensitive tables to ignore
21
+ MaxAllowedPacket: Sets the largest packet size to use in backups
22
+ LockTables: Lock all tables for the duration of the dump
22
23
*/
23
24
type Data struct {
24
25
Out io.Writer
@@ -130,6 +131,9 @@ func (data *Data) Dump() error {
130
131
return err
131
132
}
132
133
134
+ // Start the read only transaction and defer the rollback until the end
135
+ // This way the database will have the exact state it did at the begining of
136
+ // the backup and nothing can be accidentally committed
133
137
if err := data .begin (); err != nil {
134
138
return err
135
139
}
@@ -181,6 +185,8 @@ func (data *Data) Dump() error {
181
185
182
186
// MARK: - Private methods
183
187
188
+ // begin starts a read only transaction that will be whatever the database was
189
+ // when it was called
184
190
func (data * Data ) begin () (err error ) {
185
191
data .tx , err = data .Connection .BeginTx (context .Background (), & sql.TxOptions {
186
192
Isolation : sql .LevelRepeatableRead ,
@@ -189,6 +195,7 @@ func (data *Data) begin() (err error) {
189
195
return
190
196
}
191
197
198
+ // rollback cancels the transaction
192
199
func (data * Data ) rollback () error {
193
200
return data .tx .Rollback ()
194
201
}
@@ -294,7 +301,6 @@ func (table *table) CreateSQL() (string, error) {
294
301
return tableSQL .String , nil
295
302
}
296
303
297
- // defer rows.Close()
298
304
func (table * table ) Init () (err error ) {
299
305
if len (table .types ) != 0 {
300
306
return errors .New ("can't init twice" )
0 commit comments