Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(database-pg): Fixed the issue of PostgreSQL not being able to back up. #7324

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions backend/utils/postgresql/client/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"
"os/exec"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -134,7 +135,7 @@ func (r *Remote) Backup(info BackupInfo) error {
}
fileNameItem := info.TargetDir + "/" + strings.TrimSuffix(info.FileName, ".gz")
backupCommand := exec.Command("bash", "-c",
fmt.Sprintf("docker run --rm --net=host -i %s -e PGPASSWORD='%s' /bin/bash -c 'pg_dump -h %s -p %d --no-owner -Fc -U %s %s' > %s",
fmt.Sprintf("docker run --rm --net=host -i %s /bin/bash -c 'PGPASSWORD=%s pg_dump -h %s -p %d --no-owner -Fc -U %s %s' > %s",
imageTag, r.Password, r.Address, r.Port, r.User, info.Name, fileNameItem))
_ = backupCommand.Run()
b := make([]byte, 5)
Expand Down Expand Up @@ -177,7 +178,7 @@ func (r *Remote) Recover(info RecoverInfo) error {
}()
}
recoverCommand := exec.Command("bash", "-c",
fmt.Sprintf("docker run --rm --net=host -i %s -e PGPASSWORD='%s' /bin/bash -c 'pg_restore -h %s -p %d --verbose --clean --no-privileges --no-owner -Fc -U %s -d %s --role=%s' < %s",
fmt.Sprintf("docker run --rm --net=host -i %s /bin/bash -c 'PGPASSWORD=%s pg_restore -h %s -p %d --verbose --clean --no-privileges --no-owner -Fc -U %s -d %s --role=%s' < %s",
imageTag, r.Password, r.Address, r.Port, r.User, info.Name, info.Username, fileName))
pipe, _ := recoverCommand.StdoutPipe()
stderrPipe, _ := recoverCommand.StderrPipe()
Expand Down Expand Up @@ -296,7 +297,11 @@ func loadImageTag() (string, error) {
return itemTag, nil
}

itemTag = "postgres:16.1-alpine"
sort.Strings(versions)
if len(versions) != 0 {
itemTag = versions[len(versions)-1]
}

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
defer cancel()
if _, err := client.ImagePull(ctx, itemTag, image.PullOptions{}); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like there are a few issues with the code that need to be addressed:

  1. The Backup function has some syntax errors related to missing closing quotes and incorrect braces.
  2. It is important not to use the same file name across multiple docker commands when using Docker. Using a unique filename for each command can help avoid conflicts and ensure they work correctly together.

To address these issues, here's how you might refactor it:

  • Make sure to always enclose variable and string values within quotes.
  • Use single-bracket {} instead of double-bracket {...} for better readability and maintainability.

Also, note that imagePull() only works reliably if your Docker daemon supports this method. If you're trying to access images from a remote registry URL (like Docker Hub), consider setting up an account there directly or using local storage in development environments so you could pull locally available images easily without having to use external sources which might have less control over network security and authentication checks. Please refer to official Docker documentation or Stack Overflow for more details about Docker Daemon settings, especially regarding network configuration (net) option under registry.

Regarding versioning logic, I believe your intention was to sort all versions alphabetically before selecting one. Ensure that this is correct according to what you intended based on the task requirements.

Lastly, please let me know if you want me to further break down specific parts or explain concepts deeper since no exact issue descriptions are mentioned above.

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,7 @@ const message = {
gotoInstalled: 'Go to install',
search: 'Search',
limitHelper: 'The application has already been installed.',
deleteHelper: `"{0}" has been associated with the following resource(s) and can't be deleted`,
deleteHelper: `"{0}" has been associated with the following resource(s). Please check and try again!`,
checkTitle: 'Hint',
website: 'website',
database: 'database',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None found

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ const message = {
gotoInstalled: '去安裝',
search: '搜索',
limitHelper: '該應用已安裝,不支持重復安裝',
deleteHelper: '{0}已經關聯以下資源,無法刪除',
deleteHelper: '{0}已經關聯以下資源,請檢查後重試!',
checkTitle: '提示',
website: '網站',
database: '數據庫',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes suggested here may require testing to confirm their impact on performance and security. Please test the updated files in different environments (local/production) with both positive and negative load cases before implementing them.

If you encounter any unexpected issues during testing such as errors or system crashes, please provide detailed information about each environment's configuration details including operating systems, network conditions, etc., so I could further analyze whether we need an adjustment at this stage of deployment.

For optimizing memory usage, consider compressing some commonly used data structures like arrays instead of creating copies repeatedly in loops. However, do verify that these changes don’t affect backward compatibility if there is existing data that relies on those specific array copies.

// Your previous code file path here

const message = {
        // Rest of your existing variables remain unchanged...
};

if(process.argv.length < 3){
  console.log("Incorrect input given!");
  process.exit(1);
}

let argvs = process.argv.slice(2);

for(let i = 0; i <= argvs.indexOf('-p'); ++i){
    var value = Number(argvs[i]);
    
    switch(value %1){
      case true:
          message[value]--;
          break;
      default:
          message[value]++;
          break;
    }
}

console.log(message);

Note that without actual code execution context, it's hard to give more accurate results.

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,7 @@ const message = {
gotoInstalled: '去安装',
search: '搜索',
limitHelper: '该应用已安装,不支持重复安装',
deleteHelper: '{0}已经关联以下资源,无法删除',
deleteHelper: '{0}已经关联以下资源,请检查后重试!',
checkTitle: '提示',
website: '网站',
database: '数据库',
Expand Down
Loading