Skip to content

Instantly share code, notes, and snippets.

@bzin
Last active August 23, 2022 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bzin/fff1a302eda4afc4ec15a33a0512666b to your computer and use it in GitHub Desktop.
Save bzin/fff1a302eda4afc4ec15a33a0512666b to your computer and use it in GitHub Desktop.
CLI commands and other snippets that I use all the time

Server backups (utils commands)

Use the below CLI commands to backup important files in a server.

PS: have in mind that this assumes a specific folder structure

cd / && tar -zcf /data/backup/server_etc_[project-name]_prod_backup_[date].tar.gz etc
cd /data && tar -zcf /data/backup/projects_[project-name]_prod_backup_[date].tar.gz projects
cd backup/ && mysqldump --all-databases --single-transaction --quick --lock-tables=false > full-[project-name]-backup-$(date +%F).sql -u root -p

Database backup for MariaDB and Mysql

Full backup of your databases

mysqldump --all-databases --single-transaction --quick --lock-tables=false > full-backup-$(date +%F).sql -u root -p

Links

Zip folders and files in server

tar -zcvf archive-name.tar.gz directory-name

Links

Access to shells file to update used bash

sudo nano /etc/shells 

Open /etc/shells from CLI

chsh

Links

Create symbolic link (to some extend... a shortcurt)

Some info regarding its options can be found on ln Linux manual

ln -s <correct_path> <shortcut_location>

More about this in article How to Create Symbolic Links Using the ln Command

Status Apache server

Start & Stop services on CentOS 7

systemctl status httpd

Restart Apache server

systemctl restart httpd

Check vhosts configuration

Stack Overflow source

httpd -t

Set a 302 redirection on vhost / htaccess

# Redirection
RewriteBase /
RewriteRule ^old-url.html(/.*)?$ new-ur$1 [R=302,L]

Set a 302 redirection on nginx vhost

server {
   # Create redirections of /some-path/url -> /url
   rewrite ^/some-path/(.*)$ https://$host/$1;
}

See more about nginx configuration here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment