How do you back up a database in SQL Server, PostgreSQL, or MySQL?
SQL Server:
To back up a database in SQL Server, you can use the BACKUP DATABASE command.
- - Full Backup
BACKUP DATABASE MyDatabase TO DISK = 'C:\Backups\MyDatabase.bak';
- - Transaction Log Backup
BACKUP LOG MyDatabase TO DISK = 'C:\Backups\MyDatabase_log.trn';
PostgreSQL:
In PostgreSQL, you can use the pg_dump command for backing up the database.
- - Full Backup
pg_dump mydatabase > /path/to/backup/mydatabase.sql
For backing up with compression or other options:
pg_dump -Fc mydatabase > /path/to/backup/mydatabase.dump
For transactional backups, you can use WAL (Write-Ahead Logging) archiving, typically
managed through archive_mode and archive_command settings in the
postgresql.conf.
MySQL:
In MySQL, you can use the mysqldump command for backing up the database.
- - Full Backup
mysqldump -u username -p mydatabase > /path/to/backup/mydatabase.sql
For binary logging (transaction logs), MySQL uses binlog:
- - Enabling binary log
[mysqld]
log-bin=mysql-bin