Exemple #1
0
func DoBackup(app *GoInk.App) (string, error) {
	os.Mkdir(backupDir, os.ModePerm)
	filename := path.Join(backupDir, utils.DateTime(time.Now(), "YYYYMMDDHHmmss.zip"))
	z, e := zip.Create(filename)
	if e != nil {
		return "", e
	}
	root, _ := os.Getwd()
	z.AddDir("static", path.Join(root, "static"))
	z.AddDir("data", path.Join(root, "data"))
	z.AddDir(app.View().Dir, path.Join(root, app.View().Dir))
	e = z.Flush()
	if e != nil {
		return "", e
	}
	println("backup success in " + filename)
	return filename, nil
}
Exemple #2
0
// DoBackup backups whole files to zip archive.
// If withData is false, it compresses static files to zip archive without data files, config files and install lock file.
func DoBackup(app *GoInk.App, withData bool) (string, error) {
	os.Mkdir(backupDir, os.ModePerm)
	// create zip file name from time unix
	filename := path.Join(backupDir, utils.DateTime(time.Now(), "YYYYMMDDHHmmss"))
	if withData {
		filename += ".zip"
	} else {
		filename += "_static.zip"
	}
	z, e := zip.Create(filename)
	if e != nil {
		return "", e
	}
	root, _ := os.Getwd()
	if withData {
		// if with data, add install lock file and config file
		lockFile := path.Join(root, "install.lock")
		if utils.IsFile(lockFile) {
			z.AddFile("install.lock", lockFile)
		}
		configFile := path.Join(root, "config.json")
		if utils.IsFile(configFile) {
			z.AddFile("config.json", configFile)
		}
	}
	z.AddDir("static/css", path.Join(root, "static", "css"))
	z.AddDir("static/img", path.Join(root, "static", "img"))
	z.AddDir("static/js", path.Join(root, "static", "js"))
	z.AddDir("static/lib", path.Join(root, "static", "lib"))
	z.AddFile("static/favicon.ico", path.Join(root, "static", "favicon.ico"))
	if withData {
		// if with data, backup data files and uploaded files
		z.AddDir("data", path.Join(root, "data"))
		z.AddDir("static/upload", path.Join(root, "static", "upload"))
	}
	z.AddDir(app.View().Dir, path.Join(root, app.View().Dir))
	e = z.Flush()
	if e != nil {
		return "", e
	}
	println("backup success in " + filename)
	return filename, nil
}