scp and rsync copy files over SSH. Use them for configs, scripts, backups, worlds, and server folders when SFTP is not convenient.

scp is best for quick one-off copies. rsync is better for repeated syncs because it can copy only changed files, preserve permissions, exclude folders, preview changes, and mirror deletions when you ask it to.

 

Copy one file with scp

scp ./server.cfg username@VPS_IP_ADDRESS:/home/username/server.cfg

 

Copy a folder with scp

scp -r ./world username@VPS_IP_ADDRESS:/home/username/world

 

Use a custom SSH port with scp

scp uses an uppercase -P for the SSH port:

scp -P 2222 ./server.cfg username@VPS_IP_ADDRESS:/home/username/server.cfg

 

Use an SSH key with scp

scp -i ~/.ssh/mykey ./server.cfg username@VPS_IP_ADDRESS:/home/username/server.cfg

 

Sync a folder with rsync

rsync -avz ./world/ username@VPS_IP_ADDRESS:/home/username/world/

The trailing slash matters. ./world/ copies the contents of the folder into the destination folder. Without the trailing slash, rsync copies the folder itself into the destination.

 

Preview an rsync before copying

Use --dry-run when you want to check what would change before touching the remote files:

rsync -avz --dry-run ./world/ username@VPS_IP_ADDRESS:/home/username/world/

Linux terminal showing an rsync dry run before copying files to a VPS

 

Mirror a folder exactly

--delete removes remote files that no longer exist locally. This is useful for exact mirrors, but dangerous if you point it at the wrong folder.

rsync -avz --delete ./world/ username@VPS_IP_ADDRESS:/home/username/world/

Run the same command with --dry-run first if you are using --delete.

 

Exclude files or folders

Exclude logs, cache folders, temporary files, or generated files you do not want to copy:

rsync -avz --exclude "logs/" --exclude "*.tmp" ./server/ username@VPS_IP_ADDRESS:/home/username/server/

 

Use a custom SSH port with rsync

rsync passes SSH options through -e:

rsync -avz -e "ssh -p 2222" ./server/ username@VPS_IP_ADDRESS:/home/username/server/

 

Use an SSH key with rsync

rsync -avz -e "ssh -i ~/.ssh/mykey" ./server/ username@VPS_IP_ADDRESS:/home/username/server/

 

Copy from the VPS back to your PC

Reverse the source and destination when downloading a folder from the VPS:

rsync -avz username@VPS_IP_ADDRESS:/home/username/world/ ./world-backup/

 

Useful rsync options

OptionWhat it does
-aArchive mode. Preserves folders, permissions, timestamps, and symlinks.
-vVerbose output, so you can see what is being copied.
-zCompress data during transfer. Useful on slower connections.
--progressShows copy progress for large files.
--dry-runShows what would happen without changing files.
--deleteDeletes remote files that are not present in the source.
--excludeSkips matching files or folders.

 

When to use each

ToolBest for
scpSimple one-off file or folder copies.
rsyncRepeated syncs, larger folders, backups, excludes, dry-runs, and copying only changed files.

Stop the game server before replacing live world files, database files, or saves. Take a backup first if you are using --delete or copying over an existing world.

  • 0 Utilisateurs l'ont trouvée utile
Cette réponse était-elle pertinente?

Articles connexes

How to connect to a Linux VPS with SSH

SSH is the normal way to manage a Linux VPS. It gives you a terminal on the server so you can...

How to update packages on a Linux VPS

Keeping packages updated helps patch security issues and keeps server tools compatible. Run...

How to create a sudo user on a Linux VPS

A sudo user lets you manage a Linux VPS without logging in as root for every task. This is safer...

How to secure SSH on a Linux VPS

SSH is the main way to manage a Linux VPS, so it should be secured before the server is used for...

How to check disk usage on a Linux VPS

Disk usage issues can stop updates, backups, logs, databases, and game saves from writing...