Introduction | db-dumper-go | Spatie       

 SPATIE  

db-dumper-go
============

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Db-dumper-go](https://spatie.be/docs/db-dumper-go/v1)  Introduction

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/db-dumper-go/v1) 

  Introduction    
- [ Introduction ](https://spatie.be/docs/db-dumper-go/v1/introduction)
- [ Requirements ](https://spatie.be/docs/db-dumper-go/v1/requirements)
- [ Installation and setup ](https://spatie.be/docs/db-dumper-go/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/db-dumper-go/v1/usage)
- [ Processes and output ](https://spatie.be/docs/db-dumper-go/v1/processes-and-output)
- [ Testing ](https://spatie.be/docs/db-dumper-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/db-dumper-go/v1/releasing)
- [ Contributing ](https://spatie.be/docs/db-dumper-go/v1/contributing)
- [ Security vulnerabilities ](https://spatie.be/docs/db-dumper-go/v1/security-vulnerabilities)
- [ Credits ](https://spatie.be/docs/db-dumper-go/v1/credits)
- [ License ](https://spatie.be/docs/db-dumper-go/v1/license)
- [ Changelog ](https://spatie.be/docs/db-dumper-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/db-dumper-go/v1/support-us)

  Db-dumper-go 
==============

 Dump databases from Go 

### Useful links

- [Repository](https://github.com/spatie/db-dumper-go)
- [Discussions](https://github.com/spatie/db-dumper-go/discussions)

Introduction
------------

This package contains an easy to use dumper to dump a database using Go. Currently MySQL, MariaDB, PostgreSQL, SQLite and MongoDB are supported. Behind the scenes `mysqldump`, `mariadb-dump`, `pg_dump`, `sqlite3` and `mongodump` are used.

Here are simple examples of how to create a database dump with different drivers. Each example assumes a `context.Context` named `ctx` and imports `github.com/spatie/db-dumper-go` as `dbdumper`.

**MySQL**

```
dumper := dbdumper.New(dbdumper.MySQL)
dumper.DBName = databaseName
dumper.UserName = userName
dumper.Password = password
err := dumper.DumpToFile(ctx, "dump.sql")
```

**MariaDB**

```
dumper := dbdumper.New(dbdumper.MariaDB)
dumper.DBName = databaseName
dumper.UserName = userName
dumper.Password = password
err := dumper.DumpToFile(ctx, "dump.sql")
```

**PostgreSQL**

```
dumper := dbdumper.New(dbdumper.PostgreSQL)
dumper.DBName = databaseName
dumper.UserName = userName
dumper.Password = password
err := dumper.DumpToFile(ctx, "dump.sql")
```

**SQLite**

```
dumper := dbdumper.New(dbdumper.SQLite)
dumper.DBName = pathToDatabaseFile
err := dumper.DumpToFile(ctx, "dump.sql")
```

**MongoDB**

```
dumper := dbdumper.New(dbdumper.MongoDB)
dumper.DBName = databaseName
dumper.UserName = userName
dumper.Password = password
err := dumper.DumpToFile(ctx, "dump.archive")
```

Check the returned error before using the dump. MongoDB writes a binary archive, not SQL. A `.gz` filename alone does not enable compression.

Start with [requirements](requirements) and [installation](installation-and-setup), then read [usage](usage).

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
