J
If you delete all data on your PS4, that data is lost if not backed up. Your account, the games you bought, and your trophies will remain on Sony's servers, but you will lose any progress made in your games.
There are 2 ways to back up your save data.
Manually, by inserting a USB storage device and copying your save data over.
Automatically, using the PS Plus cloud storage. This requires subscribing to a paid membership for PS Plus. According to https://gaming.stackexchange.com/a/23318/46740 , if your membership expires, your data will be inaccessible until you subscribe again. If you don't renew your membership within 6 months of expiration, your data will be deleted.
This means that if you intend to resume your games years after you factory reset your PS4, you will either need to copy your save data on a USB storage device, or renew your PS Plus subscription every 6 months to avoid auto-deletion.
Note that if you choose to use the cloud storage, it is recommended to manually copy your data to the cloud before factory resetting your console. That's because the PS4 performs its automatic upload when you log out of PSN (such as when the system enters rest mode) [ https://manuals.playstation.net/document/en/ps4/settings/data_upload.html ], rather than when you exit the game or when the save data is created or modified.