@@ -42,8 +42,8 @@ portable among all supported database engines.`,
42
42
},
43
43
}
44
44
45
- const _CURRENT_BACKUP_FORMAT_VERSION = 1
46
- const _ARCHIVE_ROOT_DIR = "gogs-backup"
45
+ const currentBackupFormatVersion = 1
46
+ const archiveRootDir = "gogs-backup"
47
47
48
48
func runBackup (c * cli.Context ) error {
49
49
zip .Verbose = c .Bool ("verbose" )
@@ -54,7 +54,8 @@ func runBackup(c *cli.Context) error {
54
54
}
55
55
conf .InitLogging (true )
56
56
57
- if err = db .SetEngine (); err != nil {
57
+ conn , err := db .SetEngine ()
58
+ if err != nil {
58
59
return errors .Wrap (err , "set engine" )
59
60
}
60
61
@@ -71,7 +72,7 @@ func runBackup(c *cli.Context) error {
71
72
// Metadata
72
73
metaFile := path .Join (rootDir , "metadata.ini" )
73
74
metadata := ini .Empty ()
74
- metadata .Section ("" ).Key ("VERSION" ).SetValue (com .ToStr (_CURRENT_BACKUP_FORMAT_VERSION ))
75
+ metadata .Section ("" ).Key ("VERSION" ).SetValue (com .ToStr (currentBackupFormatVersion ))
75
76
metadata .Section ("" ).Key ("DATE_TIME" ).SetValue (time .Now ().String ())
76
77
metadata .Section ("" ).Key ("GOGS_VERSION" ).SetValue (conf .App .Version )
77
78
if err = metadata .SaveTo (metaFile ); err != nil {
@@ -85,22 +86,22 @@ func runBackup(c *cli.Context) error {
85
86
if err != nil {
86
87
log .Fatal ("Failed to create backup archive '%s': %v" , archiveName , err )
87
88
}
88
- if err = z .AddFile (_ARCHIVE_ROOT_DIR + "/metadata.ini" , metaFile ); err != nil {
89
+ if err = z .AddFile (archiveRootDir + "/metadata.ini" , metaFile ); err != nil {
89
90
log .Fatal ("Failed to include 'metadata.ini': %v" , err )
90
91
}
91
92
92
93
// Database
93
94
dbDir := filepath .Join (rootDir , "db" )
94
- if err = db .DumpDatabase (dbDir ); err != nil {
95
+ if err = db .DumpDatabase (conn , dbDir , c . Bool ( "verbose" ) ); err != nil {
95
96
log .Fatal ("Failed to dump database: %v" , err )
96
97
}
97
- if err = z .AddDir (_ARCHIVE_ROOT_DIR + "/db" , dbDir ); err != nil {
98
+ if err = z .AddDir (archiveRootDir + "/db" , dbDir ); err != nil {
98
99
log .Fatal ("Failed to include 'db': %v" , err )
99
100
}
100
101
101
102
// Custom files
102
103
if ! c .Bool ("database-only" ) {
103
- if err = z .AddDir (_ARCHIVE_ROOT_DIR + "/custom" , conf .CustomDir ()); err != nil {
104
+ if err = z .AddDir (archiveRootDir + "/custom" , conf .CustomDir ()); err != nil {
104
105
log .Fatal ("Failed to include 'custom': %v" , err )
105
106
}
106
107
}
@@ -113,7 +114,7 @@ func runBackup(c *cli.Context) error {
113
114
continue
114
115
}
115
116
116
- if err = z .AddDir (path .Join (_ARCHIVE_ROOT_DIR + "/data" , dir ), dirPath ); err != nil {
117
+ if err = z .AddDir (path .Join (archiveRootDir + "/data" , dir ), dirPath ); err != nil {
117
118
log .Fatal ("Failed to include 'data': %v" , err )
118
119
}
119
120
}
@@ -149,7 +150,7 @@ func runBackup(c *cli.Context) error {
149
150
}
150
151
log .Info ("Repositories dumped to: %s" , reposDump )
151
152
152
- if err = z .AddFile (_ARCHIVE_ROOT_DIR + "/repositories.zip" , reposDump ); err != nil {
153
+ if err = z .AddFile (archiveRootDir + "/repositories.zip" , reposDump ); err != nil {
153
154
log .Fatal ("Failed to include %q: %v" , reposDump , err )
154
155
}
155
156
}
@@ -158,7 +159,7 @@ func runBackup(c *cli.Context) error {
158
159
log .Fatal ("Failed to save backup archive '%s': %v" , archiveName , err )
159
160
}
160
161
161
- os .RemoveAll (rootDir )
162
+ _ = os .RemoveAll (rootDir )
162
163
log .Info ("Backup succeed! Archive is located at: %s" , archiveName )
163
164
log .Stop ()
164
165
return nil
0 commit comments