Error 21 isn't very specific and hardly identifies the issue.
To confirm, you have an older version of iOS? Please clarify what OS you have atm.
Backing up the phone is rather useless I find. Your backup is a backup of iOS at THAT firmware. You backup 4.3.2 fw, and install 5.0.1, then "restore" your backup, you will jump right back to 4.3.2 (assuming you have shsh and set hosts to cydia/tinyumbrella).
I would just do this if I were you.
Before updating:
>>Assuming you are already jailbroken, download "DataDeposit" a free cydia app that backsup your appdata, like settings, or gamesaves, to your linked dropbox account.
>>Backup any apps/games you would like to keep your save data for.
>>Then you can restore that data after you are fully updated.
Now begin the restore/update process:
>>Plug your 3gs into your PC, and startup iTunes WITHOUT using cydia hosts, or tinyumbrella.
>>Do a clean restore to iOS 5.0.1 via iTunes.
>>If you have 5.0.1 ipsw downloaded already, you can use shift+restore to manually select the stock 5.0.1 ipsw
I highly recommend manually downloading it, if you wish to avoid downloading it multiple times through itunes, should your restore fail for whatever reason. I just trust manual more.
>>If an error code shows up, and you can not figure out how to resolve it yourself, try coming back here, and posting your results with more information
>>You should now be restored to stock 5.0.1, and it will not be activated. If you need your phone unlocked to use it, do not worry. Proceed to the next step.
>>Jailbreak with redsn0w. This will activate the iPhone for you during the process, it will jailbreak you untethered, and everything should work at that point. You may have to run initial setup steps (set up wifi, icloud, location services, etc.) before using.
>>When you are done, sync with iTunes as a new iPhone, resync all your old apps, and download the cydia app "DataDeposit," link it up with dropbox, and restore all your old appdata.
I hope this helps you, it may be a bit of a hassle, but I had umpteen thousand error codes when trying to update, and this process was the only way I found success.