seafile_recovery/seafile_recovery.go

66 lines
1.9 KiB
Go
Raw Normal View History

2021-04-21 12:25:35 +00:00
package main
import (
"log"
"github.com/docopt/docopt-go"
)
func main() {
usage := `Seafile Recovery.
Usage:
2021-04-22 09:29:04 +00:00
seafile_recovery [--storage=<sto>] head <repoid>
2021-04-23 15:33:32 +00:00
seafile_recovery [--storage=<sto>] ls <repoid> (--dir=<dirid> | --file=<fileid>)
2021-04-26 09:05:31 +00:00
seafile_recovery [--storage=<sto>] cp <repoid> (--dir=<dirid> | --file=<fileid>) <dest>
seafile_recovery [--storage=<sto>] s3 <repoid> (--dir=<dirid> | --file=<pathid>) <dest>
2021-04-21 12:25:35 +00:00
seafile_recovery (-h | --help)
Options:
2021-04-23 15:33:32 +00:00
-h --help Show this screen
--storage=<sto> Set Seafile storage path [default: ./storage]
--dir=<dirid> Seafile Directory ID, can be obtained from commits as RootID
--file=<fileid> Seafile File ID, can be obtained through ls
`
2021-04-21 12:25:35 +00:00
2021-04-23 14:44:42 +00:00
config := new(configCollect)
2021-04-21 12:25:35 +00:00
opts, err := docopt.ParseDoc(usage)
if err != nil { log.Fatal(err) }
2021-04-23 14:44:42 +00:00
opts.Bind(config)
2021-04-21 12:25:35 +00:00
2021-04-21 12:44:49 +00:00
checkRootFolder(config.Storage)
2021-04-21 13:54:50 +00:00
rexists := repoExistsIn(config.Storage, config.RepoId)
2021-04-21 12:44:49 +00:00
2021-04-22 09:29:04 +00:00
if config.Head {
2021-04-21 13:54:50 +00:00
if !rexists["commits"] { log.Fatal("No commits folder found for repo ",config.RepoId) }
2021-04-22 09:29:04 +00:00
cmdHead(config)
2021-04-22 10:38:52 +00:00
} else if config.Ls {
if !rexists["fs"] { log.Fatal("No fs folder found for repo ",config.RepoId) }
2021-04-23 15:33:32 +00:00
if len(config.DirId) > 0 {
cmdLs(config)
} else {
2021-04-24 09:09:15 +00:00
cmdInfo(config)
2021-04-23 15:33:32 +00:00
}
} else if config.Cp {
2021-04-22 10:38:52 +00:00
if !rexists["fs"] { log.Fatal("No fs folder found for repo ",config.RepoId) }
if !rexists["blocks"] { log.Fatal("No blocks folder found for repo ",config.RepoId) }
2021-04-26 09:05:31 +00:00
if len(config.DirId) > 0 {
cmdCpDir(config)
} else {
cmdCpFile(config)
}
2021-04-22 10:38:52 +00:00
} else if config.S3 {
if !rexists["fs"] { log.Fatal("No fs folder found for repo ",config.RepoId) }
if !rexists["blocks"] { log.Fatal("No blocks folder found for repo ",config.RepoId) }
2021-04-26 16:39:54 +00:00
if len(config.DirId) > 0 {
cmdS3Dir(config)
} else {
cmdS3File(config)
}
2021-04-21 12:44:49 +00:00
} else {
log.Fatal("This command is not implemented")
}
2021-04-21 12:25:35 +00:00
}