{"id":26769465,"url":"https://github.com/sypper-pit/postgresql-backup-ftp","last_synced_at":"2026-04-29T22:43:33.137Z","repository":{"id":227902307,"uuid":"772675293","full_name":"sypper-pit/postgresql-backup-ftp","owner":"sypper-pit","description":"This script facilitates automated backups of a PostgreSQL database in Docker, handles their upload to FTP, and manages backup file retention by deleting old files.","archived":false,"fork":false,"pushed_at":"2024-03-15T20:27:30.000Z","size":33,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-28T22:35:01.187Z","etag":null,"topics":["backup-script","bash-script","docker","ftp","postgresql"],"latest_commit_sha":null,"homepage":"https://cctv-m.ru/pgsql-bash-backup","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sypper-pit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-15T16:59:51.000Z","updated_at":"2024-06-14T17:14:41.000Z","dependencies_parsed_at":"2024-03-15T18:28:46.186Z","dependency_job_id":"556eee92-31f3-4123-8045-4ab05150d838","html_url":"https://github.com/sypper-pit/postgresql-backup-ftp","commit_stats":null,"previous_names":["sypper-pit/postgresql-backup-ftp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sypper-pit/postgresql-backup-ftp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sypper-pit%2Fpostgresql-backup-ftp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sypper-pit%2Fpostgresql-backup-ftp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sypper-pit%2Fpostgresql-backup-ftp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sypper-pit%2Fpostgresql-backup-ftp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sypper-pit","download_url":"https://codeload.github.com/sypper-pit/postgresql-backup-ftp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sypper-pit%2Fpostgresql-backup-ftp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262558034,"owners_count":23328441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backup-script","bash-script","docker","ftp","postgresql"],"created_at":"2025-03-28T22:31:42.901Z","updated_at":"2025-10-26T18:02:12.065Z","avatar_url":"https://github.com/sypper-pit.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"BTC: bc1qttzg9yww3nv5dg2d5ja95txmt0mrw9dltfqj57\n\nMonero(XMR): 8AyWrMwPCxrcbcmVDj3Y5RCfcSQtBBVE2JK9qJ4WqrPpaoa3uNvLReQXPXGj7D5zEsMjBKeWWdyDD4gerqzTtKKS36zSfnM\n\nLTC: LfMJCyxxg65sA3X9XEze157D16ztszndqk\n\nUSDT(TRC-20): TTZGfnhurU62VRRGYUHMPJ8q6U8rn5xG5a\n\nUSDT(ERC-20): 0xbdfec67586a78e5d3b58dfb70aa181823c8deafa\n\nDOGE: D6kb8jcVXYTi82nsoACAYKYhtA5EJ4D9Jg\n\n# Backup and Cleanup Script for PostgreSQL in Docker with FTP Upload\n\n## Overview\nThis guide explains how to modify a Bash script for backing up a PostgreSQL database inside a Docker container, uploading the backup to an FTP server, and deleting old backup files.\n\n## Prerequisites\n- Docker installed\n- Access to a PostgreSQL container\n- FTP server credentials\n\n## Steps\n0. **Install pack on ubuntu**\n   \n    ```bash\n    sudo apt install curl lftp\n    ```\n\n2. **Set Variables**: Define variables for directory paths, container names, database details, and FTP credentials at the beginning of your script.\n\n    ```bash\n    BACKUP_DIR=\"/path/to/backup\"\n    CONTAINER_NAME_PART=\"db-container-name-part\"\n    POSTGRES_DB=\"your_db_name\"\n    POSTGRES_USER=\"your_db_user\"\n    FTP_USER=\"your_ftp_user\"\n    FTP_PASSWORD=\"your_ftp_password\"\n    FTP_HOST=\"ftp.server.com\"\n    FTP_DIR=\"/path/on/ftp\"\n    DAYS_OLD=7\n    ```\n\n3. **Find Container ID**: Use `docker ps` to find your container's ID by matching part of its name.\n\n    ```bash\n    CONTAINER_ID=$(docker ps | grep $CONTAINER_NAME_PART | awk '{print $1}')\n    ```\n\n4. **Backup Database**: Perform the `pg_dump` command inside your container to create the backup.\n\n    ```bash\n    docker exec -e PGPASSWORD=$POSTGRES_PASSWORD $CONTAINER_ID pg_dump -U $POSTGRES_USER $POSTGRES_DB \u003e $BACKUP_FILE_NAME\n    ```\n\n5. **Upload to FTP**: Use `curl` to upload the backup file to your FTP server.\n\n    ```bash\n    curl -T ${BACKUP_FILE_NAME} --user ${FTP_USER}:${FTP_PASSWORD} ftp://${FTP_HOST}${FTP_DIR}/\n    ```\n\n6. **Delete Old Files Locally**: Use `find` to delete backup files older than `DAYS_OLD` days.\n\n    ```bash\n    find $BACKUP_DIR -type f -name \"*.sql\" -mtime +$DAYS_OLD -exec rm {} \\;\n    ```\n\n7. **Delete Old Files on FTP**: Utilize `lftp` to connect to the FTP server and delete old files.\n\n    ```bash\n    lftp -u ${FTP_USER},${FTP_PASSWORD} ${FTP_HOST} \u003c\u003cEOF\n    set ssl:verify-certificate no\n    cd ${FTP_DIR}\n    cls -1 --sort=date | awk 'NR\u003e$DAYS_OLD' | xargs -r -d '\\n' rm\n    bye\n    EOF\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsypper-pit%2Fpostgresql-backup-ftp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsypper-pit%2Fpostgresql-backup-ftp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsypper-pit%2Fpostgresql-backup-ftp/lists"}