HOW TO SET UP LOCAL BACKUPS FOR DATABASES AND PROJECT FILES USING SCRIPTS?
Reliable protection of code and databases is impossible without automating the backup process. For developers, having fresh copies of the local environment is critical to avoid data loss during disk failures or code errors. Setting up automatic backups using standard shell scripts allows you to fully control the information storage process without using third-party cloud services.
The first step is to write a bash script or PowerShell script that will perform archiving of the required directories and database dumps. The script defines commands for exporting MySQL or PostgreSQL databases, as well as archiving source code folders using compression utilities. It is important to add the current date and time automatically to the name of the created archive to easily find the required backup version.
To automate the execution of such a script, a task scheduler is used. In Linux operating systems, the Cron daemon is used for this purpose, where the task execution schedule is set, for example, every day at midnight. In the Windows operating system, a similar function is performed by the Task Scheduler, which allows running the created batch file with the necessary access privileges.
Regular verification of the created archives is the key to successful data recovery. It is recommended to test-deploy the backup on an isolated machine at least once a month. You should also configure backup file rotation so that old archives are automatically deleted after a certain number of days, freeing up disk space on the server or external storage.