![]() ![]() Note, you’ll need to allow sudo mysql to work without a password to automate the script. Since I use it across all my WSL instances, it uses the WSL_DISTRO_NAME environment variable to work across all of my WSL instances automatically. It includes mysqldump for my development databases and rsync for my files. This is the current version of my ~/backup.sh script. I’ve wrapped all of this up inside ~/backup.sh, which I keep synchronised between my WSL2 instances. These files are then backed up by rsyncinto Windows alongside everything else. Once it’s in a file, you can easily include this in the rsync backup.įor my daily backups, I use mysqldump to dump all of my current databases into their own files within my home directory. So the alternative is to use a tool like mysqldump to dump the database data into a file. While you could get rsync to include the raw database files, that can easily result in corrupted data. If you have any databases (such as MySQL/MariaDB), you’ll probably want to keep a backup of that data as well. You can also right click on the task in the list and select Run to manually trigger the backup to check it works. With the task fully configured, you should be able to wait for the schedule to run at the configured time. That’s it, you now have automatic backups of WSL2. ![]() You can configure the settings however suits you best. I’ll point out the settings that are important to get it working. The following screenshots show the configuration I use for my backups, customise as suits your needs. From there you can select Create Task… in the actions list on the right. It’ll keep your tasks organised and separate from the system tasks. ![]() To set up our automated backup, I’d recommend first going into the Custom folder in the left folder pane. With the Task Scheduler, we can tie our manual rsync based backup up to a schedule. Once it opens, you’ll see something that looks like this: Windows Task Scheduler You can find it by searching for Task Scheduler in the start menu, or by looking in the Windows Administrative Tools folder. Using the Task Scheduler, we can set up automatic backups for WSL2. I had no idea such a thing existed, although, in hindsight, it seems pretty logical that it would. It’s the equivalent to cron/crontab on Linux, and allows you to schedule tasks under Windows. Automating WSL2 BackupsĪfter some creative searching, I discovered the Windows Task Scheduler. Note, I haven’t tested this myself, so I don’t know the details (i.e. As an aside, I have also seen reports that cron doesn’t always run in WSL. That means cron isn’t the most reliable solution. As a result, you’ll only have backups if your WSL2 is up when your backup schedule is configured to run. Some users have suggested using cron within WSL2 to trigger periodic backups, however the cron still relies on WSL2 to be running. This method works incredibly well for getting the files into Windows where my backup program can see them and back them up properly. You’ll find my full ~/backup.sh script (with other features) at the end of this post. Additionally, I added some database backup logic, since I want my development databases backed up too. The above command is wrapped this inside ~/backup.sh, which makes it easy to call on demand – without needing to get the parameters and paths right each time. Rsync -archive -verbose -delete /home/valorin/ /mnt/c/Users/valorin/wsl2-backup/ ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |