I am working on a project in Laravel where I have to take backup of the database (mySQL).
I have learned to take backup of entire database or selected tables. But the challenge for me is to take backup of only some rows.
Here is the scenario:
There are 4 tables
- users
- posts
- tags
- post_tag
Their relations
- user
hasMany
posts and each postbelongsTo
a user - post
hasMany
Tags and a TaghasMany
posts
If if initiate backup of a user (where userId = 1
), Then I should get a backup file containing all the four tables mentioned above with data related to userId = 1
.
Also, how to restore the data?
Updates
It is a role based application. (There are 2 roles editor and author)
Editor has the privilege to backup and restore data of author.