mirror of https://github.com/1Panel-dev/1Panel
pref: 加密备份代码优化 (#5325)
parent
135ac91160
commit
e18102dfc9
|
@ -159,15 +159,13 @@ func handleTar(sourceDir, targetDir, name, exclusionRules string, secret string)
|
||||||
}
|
}
|
||||||
|
|
||||||
commands := ""
|
commands := ""
|
||||||
if secret != "" {
|
|
||||||
|
if len(secret) != 0 {
|
||||||
extraCmd := "| openssl enc -aes-256-cbc -salt -k " + secret + " -out"
|
extraCmd := "| openssl enc -aes-256-cbc -salt -k " + secret + " -out"
|
||||||
commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s %s", " -"+excludeRules, path, extraCmd, targetDir+"/"+name)
|
commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s %s", " -"+excludeRules, path, extraCmd, targetDir+"/"+name)
|
||||||
} else {
|
|
||||||
commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s", targetDir+"/"+name, excludeRules, path)
|
|
||||||
}
|
|
||||||
if len(secret) != 0 {
|
|
||||||
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
||||||
} else {
|
} else {
|
||||||
|
commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s", targetDir+"/"+name, excludeRules, path)
|
||||||
global.LOG.Debug(commands)
|
global.LOG.Debug(commands)
|
||||||
}
|
}
|
||||||
stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour)
|
stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour)
|
||||||
|
@ -187,17 +185,15 @@ func handleUnTar(sourceFile, targetDir string, secret string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commands := ""
|
commands := ""
|
||||||
if secret != "" {
|
if len(secret) != 0 {
|
||||||
extraCmd := "openssl enc -d -aes-256-cbc -k " + secret + " -in " + sourceFile + " | "
|
extraCmd := "openssl enc -d -aes-256-cbc -k " + secret + " -in " + sourceFile + " | "
|
||||||
commands = fmt.Sprintf("%s tar -zxvf - -C %s", extraCmd, targetDir+" > /dev/null 2>&1")
|
commands = fmt.Sprintf("%s tar -zxvf - -C %s", extraCmd, targetDir+" > /dev/null 2>&1")
|
||||||
} else {
|
|
||||||
commands = fmt.Sprintf("tar zxvfC %s %s", sourceFile, targetDir)
|
|
||||||
}
|
|
||||||
if len(secret) != 0 {
|
|
||||||
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
||||||
} else {
|
} else {
|
||||||
|
commands = fmt.Sprintf("tar zxvfC %s %s", sourceFile, targetDir)
|
||||||
global.LOG.Debug(commands)
|
global.LOG.Debug(commands)
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour)
|
stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
global.LOG.Errorf("do handle untar failed, stdout: %s, err: %v", stdout, err)
|
global.LOG.Errorf("do handle untar failed, stdout: %s, err: %v", stdout, err)
|
||||||
|
|
|
@ -392,15 +392,12 @@ func (u *SnapshotService) handleUnTar(sourceDir, targetDir string, secret string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commands := ""
|
commands := ""
|
||||||
if secret != "" {
|
if len(secret) != 0 {
|
||||||
extraCmd := "openssl enc -d -aes-256-cbc -k " + secret + " -in " + sourceDir + " | "
|
extraCmd := "openssl enc -d -aes-256-cbc -k " + secret + " -in " + sourceDir + " | "
|
||||||
commands = fmt.Sprintf("%s tar -zxvf - -C %s", extraCmd, targetDir+" > /dev/null 2>&1")
|
commands = fmt.Sprintf("%s tar -zxvf - -C %s", extraCmd, targetDir+" > /dev/null 2>&1")
|
||||||
} else {
|
|
||||||
commands = fmt.Sprintf("tar zxvfC %s %s", sourceDir, targetDir)
|
|
||||||
}
|
|
||||||
if len(secret) != 0 {
|
|
||||||
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
||||||
} else {
|
} else {
|
||||||
|
commands = fmt.Sprintf("tar zxvfC %s %s", sourceDir, targetDir)
|
||||||
global.LOG.Debug(commands)
|
global.LOG.Debug(commands)
|
||||||
}
|
}
|
||||||
stdout, err := cmd.ExecWithTimeOut(commands, 30*time.Minute)
|
stdout, err := cmd.ExecWithTimeOut(commands, 30*time.Minute)
|
||||||
|
|
|
@ -255,15 +255,12 @@ func handleSnapTar(sourceDir, targetDir, name, exclusionRules string, secret str
|
||||||
path = sourceDir
|
path = sourceDir
|
||||||
}
|
}
|
||||||
commands := ""
|
commands := ""
|
||||||
if secret != "" {
|
if len(secret) != 0 {
|
||||||
extraCmd := "| openssl enc -aes-256-cbc -salt -k " + secret + " -out"
|
extraCmd := "| openssl enc -aes-256-cbc -salt -k " + secret + " -out"
|
||||||
commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s %s", " -"+exStr, path, extraCmd, targetDir+"/"+name)
|
commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s %s", " -"+exStr, path, extraCmd, targetDir+"/"+name)
|
||||||
} else {
|
|
||||||
commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s -C %s .", targetDir+"/"+name, exStr, sourceDir)
|
|
||||||
}
|
|
||||||
if len(secret) != 0 {
|
|
||||||
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
||||||
} else {
|
} else {
|
||||||
|
commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s -C %s .", targetDir+"/"+name, exStr, sourceDir)
|
||||||
global.LOG.Debug(commands)
|
global.LOG.Debug(commands)
|
||||||
}
|
}
|
||||||
stdout, err := cmd.ExecWithTimeOut(commands, 30*time.Minute)
|
stdout, err := cmd.ExecWithTimeOut(commands, 30*time.Minute)
|
||||||
|
|
|
@ -19,15 +19,12 @@ func NewTarGzArchiver() ShellArchiver {
|
||||||
func (t TarGzArchiver) Extract(filePath, dstDir string, secret string) error {
|
func (t TarGzArchiver) Extract(filePath, dstDir string, secret string) error {
|
||||||
var err error
|
var err error
|
||||||
commands := ""
|
commands := ""
|
||||||
if secret != "" {
|
if len(secret) != 0 {
|
||||||
extraCmd := "openssl enc -d -aes-256-cbc -k " + secret + " -in " + filePath + " | "
|
extraCmd := "openssl enc -d -aes-256-cbc -k " + secret + " -in " + filePath + " | "
|
||||||
commands = fmt.Sprintf("%s tar -zxvf - -C %s", extraCmd, dstDir+" > /dev/null 2>&1")
|
commands = fmt.Sprintf("%s tar -zxvf - -C %s", extraCmd, dstDir+" > /dev/null 2>&1")
|
||||||
} else {
|
|
||||||
commands = fmt.Sprintf("tar -zxvf %s %s", filePath+" -C ", dstDir+" > /dev/null 2>&1")
|
|
||||||
}
|
|
||||||
if len(secret) != 0 {
|
|
||||||
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
||||||
} else {
|
} else {
|
||||||
|
commands = fmt.Sprintf("tar -zxvf %s %s", filePath+" -C ", dstDir+" > /dev/null 2>&1")
|
||||||
global.LOG.Debug(commands)
|
global.LOG.Debug(commands)
|
||||||
}
|
}
|
||||||
if err = cmd.ExecCmd(commands); err != nil {
|
if err = cmd.ExecCmd(commands); err != nil {
|
||||||
|
@ -49,15 +46,12 @@ func (t TarGzArchiver) Compress(sourcePaths []string, dstFile string, secret str
|
||||||
}
|
}
|
||||||
path += fmt.Sprintf("- -C %s %s", aheadDir, itemDir)
|
path += fmt.Sprintf("- -C %s %s", aheadDir, itemDir)
|
||||||
commands := ""
|
commands := ""
|
||||||
if secret != "" {
|
if len(secret) != 0 {
|
||||||
extraCmd := "| openssl enc -aes-256-cbc -salt -k " + secret + " -out"
|
extraCmd := "| openssl enc -aes-256-cbc -salt -k " + secret + " -out"
|
||||||
commands = fmt.Sprintf("tar -zcf %s %s %s", path, extraCmd, dstFile)
|
commands = fmt.Sprintf("tar -zcf %s %s %s", path, extraCmd, dstFile)
|
||||||
} else {
|
|
||||||
commands = fmt.Sprintf("tar -zcf %s -C %s %s", dstFile, aheadDir, itemDir)
|
|
||||||
}
|
|
||||||
if len(secret) != 0 {
|
|
||||||
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
||||||
} else {
|
} else {
|
||||||
|
commands = fmt.Sprintf("tar -zcf %s -C %s %s", dstFile, aheadDir, itemDir)
|
||||||
global.LOG.Debug(commands)
|
global.LOG.Debug(commands)
|
||||||
}
|
}
|
||||||
if err = cmd.ExecCmd(commands); err != nil {
|
if err = cmd.ExecCmd(commands); err != nil {
|
||||||
|
|
|
@ -167,7 +167,7 @@
|
||||||
</template>
|
</template>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
|
|
||||||
<OpDialog ref="opRef" @search="search">
|
<OpDialog ref="opRef" @search="search" @submit="onSubmitDelete()">
|
||||||
<template #content>
|
<template #content>
|
||||||
<el-form class="mt-4 mb-1" ref="deleteForm" label-position="left">
|
<el-form class="mt-4 mb-1" ref="deleteForm" label-position="left">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
|
@ -221,6 +221,8 @@ const isRecordShow = ref();
|
||||||
const backupOptions = ref();
|
const backupOptions = ref();
|
||||||
const accountOptions = ref();
|
const accountOptions = ref();
|
||||||
|
|
||||||
|
const operateIDs = ref();
|
||||||
|
|
||||||
type FormInstance = InstanceType<typeof ElForm>;
|
type FormInstance = InstanceType<typeof ElForm>;
|
||||||
const snapRef = ref<FormInstance>();
|
const snapRef = ref<FormInstance>();
|
||||||
const rules = reactive({
|
const rules = reactive({
|
||||||
|
@ -340,6 +342,7 @@ const batchDelete = async (row: Setting.SnapshotInfo | null) => {
|
||||||
names.push(item.name);
|
names.push(item.name);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
operateIDs.value = ids;
|
||||||
opRef.value.acceptParams({
|
opRef.value.acceptParams({
|
||||||
title: i18n.global.t('commons.button.delete'),
|
title: i18n.global.t('commons.button.delete'),
|
||||||
names: names,
|
names: names,
|
||||||
|
@ -347,8 +350,21 @@ const batchDelete = async (row: Setting.SnapshotInfo | null) => {
|
||||||
i18n.global.t('setting.snapshot'),
|
i18n.global.t('setting.snapshot'),
|
||||||
i18n.global.t('commons.button.delete'),
|
i18n.global.t('commons.button.delete'),
|
||||||
]),
|
]),
|
||||||
api: snapshotDelete,
|
api: null,
|
||||||
params: { ids: ids, deleteWithFile: cleanData.value },
|
params: null,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSubmitDelete = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
await snapshotDelete({ ids: operateIDs.value, deleteWithFile: cleanData.value })
|
||||||
|
.then(() => {
|
||||||
|
loading.value = false;
|
||||||
|
MsgSuccess(i18n.global.t('commons.msg.deleteSuccess'));
|
||||||
|
search();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
loading.value = false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue