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 := ""
|
||||
if secret != "" {
|
||||
|
||||
if len(secret) != 0 {
|
||||
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)
|
||||
} 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), "******"))
|
||||
} else {
|
||||
commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s", targetDir+"/"+name, excludeRules, path)
|
||||
global.LOG.Debug(commands)
|
||||
}
|
||||
stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour)
|
||||
|
@ -187,17 +185,15 @@ func handleUnTar(sourceFile, targetDir string, secret string) error {
|
|||
}
|
||||
}
|
||||
commands := ""
|
||||
if secret != "" {
|
||||
if len(secret) != 0 {
|
||||
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")
|
||||
} else {
|
||||
commands = fmt.Sprintf("tar zxvfC %s %s", sourceFile, targetDir)
|
||||
}
|
||||
if len(secret) != 0 {
|
||||
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
||||
} else {
|
||||
commands = fmt.Sprintf("tar zxvfC %s %s", sourceFile, targetDir)
|
||||
global.LOG.Debug(commands)
|
||||
}
|
||||
|
||||
stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour)
|
||||
if err != nil {
|
||||
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 := ""
|
||||
if secret != "" {
|
||||
if len(secret) != 0 {
|
||||
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")
|
||||
} else {
|
||||
commands = fmt.Sprintf("tar zxvfC %s %s", sourceDir, targetDir)
|
||||
}
|
||||
if len(secret) != 0 {
|
||||
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
||||
} else {
|
||||
commands = fmt.Sprintf("tar zxvfC %s %s", sourceDir, targetDir)
|
||||
global.LOG.Debug(commands)
|
||||
}
|
||||
stdout, err := cmd.ExecWithTimeOut(commands, 30*time.Minute)
|
||||
|
|
|
@ -255,15 +255,12 @@ func handleSnapTar(sourceDir, targetDir, name, exclusionRules string, secret str
|
|||
path = sourceDir
|
||||
}
|
||||
commands := ""
|
||||
if secret != "" {
|
||||
if len(secret) != 0 {
|
||||
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)
|
||||
} 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), "******"))
|
||||
} 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)
|
||||
}
|
||||
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 {
|
||||
var err error
|
||||
commands := ""
|
||||
if secret != "" {
|
||||
if len(secret) != 0 {
|
||||
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")
|
||||
} 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), "******"))
|
||||
} else {
|
||||
commands = fmt.Sprintf("tar -zxvf %s %s", filePath+" -C ", dstDir+" > /dev/null 2>&1")
|
||||
global.LOG.Debug(commands)
|
||||
}
|
||||
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)
|
||||
commands := ""
|
||||
if secret != "" {
|
||||
if len(secret) != 0 {
|
||||
extraCmd := "| openssl enc -aes-256-cbc -salt -k " + secret + " -out"
|
||||
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), "******"))
|
||||
} else {
|
||||
commands = fmt.Sprintf("tar -zcf %s -C %s %s", dstFile, aheadDir, itemDir)
|
||||
global.LOG.Debug(commands)
|
||||
}
|
||||
if err = cmd.ExecCmd(commands); err != nil {
|
||||
|
|
|
@ -167,7 +167,7 @@
|
|||
</template>
|
||||
</el-drawer>
|
||||
|
||||
<OpDialog ref="opRef" @search="search">
|
||||
<OpDialog ref="opRef" @search="search" @submit="onSubmitDelete()">
|
||||
<template #content>
|
||||
<el-form class="mt-4 mb-1" ref="deleteForm" label-position="left">
|
||||
<el-form-item>
|
||||
|
@ -221,6 +221,8 @@ const isRecordShow = ref();
|
|||
const backupOptions = ref();
|
||||
const accountOptions = ref();
|
||||
|
||||
const operateIDs = ref();
|
||||
|
||||
type FormInstance = InstanceType<typeof ElForm>;
|
||||
const snapRef = ref<FormInstance>();
|
||||
const rules = reactive({
|
||||
|
@ -340,6 +342,7 @@ const batchDelete = async (row: Setting.SnapshotInfo | null) => {
|
|||
names.push(item.name);
|
||||
});
|
||||
}
|
||||
operateIDs.value = ids;
|
||||
opRef.value.acceptParams({
|
||||
title: i18n.global.t('commons.button.delete'),
|
||||
names: names,
|
||||
|
@ -347,11 +350,24 @@ const batchDelete = async (row: Setting.SnapshotInfo | null) => {
|
|||
i18n.global.t('setting.snapshot'),
|
||||
i18n.global.t('commons.button.delete'),
|
||||
]),
|
||||
api: snapshotDelete,
|
||||
params: { ids: ids, deleteWithFile: cleanData.value },
|
||||
api: null,
|
||||
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;
|
||||
});
|
||||
};
|
||||
|
||||
function restForm() {
|
||||
if (snapRef.value) {
|
||||
snapRef.value.resetFields();
|
||||
|
|
Loading…
Reference in New Issue