Skip to main content
  1. Tech/

Backup VPS

·1 min

Here are simple steps to backup your VPS.

Backup MySQL database
#

Create a directory to store the backup files. Then run mysqldump command to backup your database.

mysqldump -u your_mysql_user -pyour_mysql_password your_database_name > /path/to/dump_$(date +\%Y\%m\%d\%H\%M\%S).sql

Or you run it as superuser and backup all databases at once.

sudo mysqldump --all-databases > /path/to/dump_$(date +\%Y\%m\%d\%H\%M\%S).sql

To automate this, schedule a cron job that will run this command on a daily basis.

crontab -e

Insert the following line to execute the mysqldump command every day at midnight.

0 0 * * * mysqldump -u your_mysql_user -pyour_mysql_password your_database_name > /path/to/dump_$(date +\%Y\%m\%d\%H\%M\%S).sql

Backup files
#

I use rsync and the following bash script to backup my files. I manually execute it from my local machine but it could easily be scheduled as a cron job and/or run from a different VPS.

#!/bin/bash

REMOTE_USER="user"
REMOTE_HOST="host"

LOCAL_BACKUP_DIR="/path/to/local/backup/directory"

# Ensure local backup directory exists
mkdir -p $LOCAL_BACKUP_DIR

rsync -avz $REMOTE_USER@$REMOTE_HOST:/path/to/database_backup $LOCAL_BACKUP_DIR/database_backup

# Backup /var/www/ and delete files that no longer exist on remote
rsync -avz --delete $REMOTE_USER@$REMOTE_HOST:/var/www/ $LOCAL_BACKUP_DIR/var_www/

echo "Backup completed."

And there you have it: a simple yet effective way to back up both your MySQL databases and essential files on your VPS.

Related

A quick script to build and deploy hugo site on VPS

·2 mins
I had been using GitHub and Netlify for this site but lack of some features such as access to server logs finally got too much. So I decided to move this blog to my VPS. One thing I really love about using Github is CI/CD and Github Actions. But I wanted something even simpler with less dependencies. So I decided to use a simple bash script to build and deploy the site.

undefined method xxxxx' for #< Hash:0x00000 >

·1 min
This error in our Rails application drove me crazy. The error was like this: undefined method xxxxxx' for #<Hash:0x000000001234> The problem was that I was calling a method like this: a_method(var: var) And the method definition was like def a_method(var: var) which resulted in something called variable shadowing and caused clash between variable passed in the method and local variable being defined. The fix was to change method definition to def a_method(var:)

Script inherits from native type 'RigidBody2D', so it can't be assigned to an object of type: 'Node2D'

·1 min
Getting this error while following this tutorial in Godot v4.0.1. In my case, I had added Node2D. The fix was to right-click on the problem node under Scene and click Make Scene Root. And then delete Node2D. Here is what diff looked like: diff --git a/2d-game-tutorial/Mob.tscn b/2d-game-tutorial/Mob.tscn index 9eb1630..e720d7f 100644 --- a/2d-game-tutorial/Mob.tscn +++ b/2d-game-tutorial/Mob.tscn @@ -48,20 +48,18 @@ animations = { radius = 36.0 height = 100.0 -node name="Mob" type="Node2D"] -script = ExtResource("1_73gb4") - -node name="RigidBody2D" type="RigidBody2D" parent="."] +node name="RigidBody2D" type="RigidBody2D"] collision_mask = 0 gravity_scale = 2.66454e-15 +script = ExtResource("1_73gb4") -node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="RigidBody2D"] +node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] scale = Vector2(0.75, 0.75) sprite_frames = SubResource("SpriteFrames_c1yjy") animation = &"walk" -node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"] +node name="CollisionShape2D" type="CollisionShape2D" parent="."] rotation = 1.5708 shape = SubResource("CapsuleShape2D_h1pjc") -node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="RigidBody2D"] +node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]