# Command createBackup fails with 22: Invalid argument

**URL:** <https://forums.percona.com/t/command-createbackup-fails-with-22-invalid-argument/8939>\
**Category:** Percona Server for MongoDB\
**Tags:** mongodb\
**Created:** [January 26, 2021, 4:09pm UTC](https://forums.percona.com/t/command-createbackup-fails-with-22-invalid-argument/8939 "2021-01-26T16:09:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajalokan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/rajalokan/32/2472_2.png) [@rajalokan](https://forums.percona.com/u/rajalokan)\
**Post date:** [January 26, 2021, 4:09pm UTC](https://forums.percona.com/t/command-createbackup-fails-with-22-invalid-argument/8939/1 "2021-01-26T16:09:56Z")

</div>

I am facing issue while running hot backup for Percona Server for Mongodb (4.0.21-16.bionic). While trying to do a basic hotbackup it fails as below

```nohighlight
rs01:SECONDARY> use admin;
switched to db admin
rs01:SECONDARY> db.runCommand({createBackup: 1, backupDir: "/home/ubuntu/hotbackups"})
{
        "ok" : 0,
        "errmsg" : "22: Invalid argument",
        "operationTime" : Timestamp(1611676494, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1611676524, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        }
}

```

I have disabled write to this secondary prior to above step by running `db.fsyncLock()`. Weird thing is that it works when if I run this `createBackup` command without locking for write.

```nohighlight
rs01:SECONDARY> use admin;                                                                                                                                                           
switched to db admin                                                                                                                                                                          
rs01:SECONDARY>                                                                                                                                                                            
rs-okan:SECONDARY> db.runCommand({createBackup: 1, backupDir: "/home/ubuntu/hotbackups"})                                                                                          
{                                                                                                                                                                                             
        "ok" : 1,                                                                                                                                                                             
        "operationTime" : Timestamp(1611674674, 1),                                                                                                                                           
        "$clusterTime" : {                                                                                                                                                                    
                "clusterTime" : Timestamp(1611674674, 1),                                                                                                                                     
                "signature" : {                                                                                                                                                               
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),                                                                                                                   
                        "keyId" : NumberLong(0)                                                                                                                                               
                }                                                                                                                                                                             
        }                                                                                                                                                                                     
}                                                                              

```

Looking at mongodb logs I see this

```auto
{
	"t": {
		"$date": "2021-01-26T23:50:12.122+05:30"
	},
	"s": "E",
	"c": "STORAGE",
	"id": 22435,
	"ctx": "conn44",
	"msg": "WiredTiger error",
	"attr": {
		"error": 22,
		"message": "[1611685212:122119][9907:0x7eff1574d700], WT_SESSION.open_cursor: __backup_start, 615: there is already a backup cursor open: Invalid argument"
	}
}

```

I know `createBackup` was added in 4.2+ and we should upgrade our mongo version but current it is a bit difficult. Fyi. To confirm this is not issue with MongoDB 4.0 , I tried this same on Percona Server for mongoDB 4.4 and it is same issue. So I’m guessing it is not something with older version of MongoDB. I might be missing something very silly here.

If anyone encountered this before or suggest for resolution. Thanks.

---

<div class="post-metadata">

**Author:** ![Igor\_Solodovnikov](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/igor_solodovnikov/32/1265_2.png) [@Igor\_Solodovnikov](https://forums.percona.com/u/Igor_Solodovnikov)\
**Post date:** [January 27, 2021, 8:23am UTC](https://forums.percona.com/t/command-createbackup-fails-with-22-invalid-argument/8939/3 "2021-01-27T08:23:19Z")

</div>

Hello @rajalokan,

You don’t need to call `db.fsyncLock()` before `createBackup` because `createBackup` handles all necessary locking internally.  
In fact fsyncLock/fsyncUnlock is absolutely independent method of doing backup so you encountered an error which should be saying something like “cannot execute createBackup while DB is fsyncLocked”.  
Definitely error messages in this situation can be improved.
