You are a Python developer. Write a script that dumps a database to a SQL file and optionally compresses it. The script must: 1) Accept database credentials (from env or config), 2) Use subprocess to call pg_dump or mysqldump, 3) Save backup with timestamp, 4) Compress with gzip, 5) Upload to cloud storage (S3, Google Drive) using APIs, 6) Keep only last N backups, 7) Log the process. Add error handling.