Add backups, currencies and dashboard APIs, and scope access by guard_name.
Web users may only CRUD their own records, operators stay in assigned branches, and admin/manager/superadmin keep full access. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0d000f9af6
commit
28509eb4ca
65 files changed
+9132
-296
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"online-back/internal/config"
|
||||
)
|
||||
|
||||
const dumpTimeout = 10 * time.Minute
|
||||
|
||||
type Dumper interface {
|
||||
Dump(ctx context.Context, destPath string) error
|
||||
}
|
||||
|
||||
type PgDumper struct {
|
||||
storage config.StorageConfig
|
||||
}
|
||||
|
||||
func NewPgDumper(storage config.StorageConfig) *PgDumper {
|
||||
return &PgDumper{storage: storage}
|
||||
}
|
||||
|
||||
func (d *PgDumper) Dump(ctx context.Context, destPath string) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, dumpTimeout)
|
||||
defer cancel()
|
||||
|
||||
cmd := exec.CommandContext(ctx, "pg_dump",
|
||||
"-h", d.storage.Host,
|
||||
"-p", d.storage.Port,
|
||||
"-U", d.storage.Username,
|
||||
"-d", d.storage.Database,
|
||||
"--no-owner",
|
||||
"--no-acl",
|
||||
"-f", destPath,
|
||||
)
|
||||
cmd.Env = append(os.Environ(), "PGPASSWORD="+d.storage.Password)
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
msg := strings.TrimSpace(string(out))
|
||||
if msg == "" {
|
||||
msg = err.Error()
|
||||
}
|
||||
if len(msg) > 512 {
|
||||
msg = msg[:512]
|
||||
}
|
||||
return fmt.Errorf("pg_dump: %s", msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user