技術情報

Useful Features of Rsync Command in Linux

Today, I would like to share about usefulness of rsync command in Linux and how to back up data with cron job. Let’s take a look.

Rsync (Remote Sync) is the most commonly used command for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems. Data can be copied, synchronized and backup both remotely and locally across directories, disks & networks.

Advantages of Rsync Command

  • It efficiently copies and sync files from source to destination remotely or locally.
  • It supports copying links, devices, owners, groups and permissions.
  • rsync allows to transfer just the differences between source and destination. The first time, it copies the whole content of a file or a directory from source to destination but from next time, it copies only the changed files/data to the destination.
  • Due to using compression and decompression method while transferring data, rsync consumes less bandwidth.

Installing Rsync

rsync is preinstalled on most Linux distributions and mac-OS. If rsync hasn’t been installed on the system, it can be installed easily using your distribution’s package manager as follows.

$ sudo apt-get install rsync [On Debian/Ubuntu & Mint]

$ pacman -S rsync [On Arch Linux]

$ emerge sys-apps/rsync [On Gentoo]

$ sudo dnf install rsync [On Fedora/CentOS/RHEL and Rocky Linux/AlmaLinux]

$ sudo zypper install rsync [On openSUSE]

Rsync Basic Command Syntax

Local to Local

rsync [OPTION] [SRC] [DEST]

Local to Remote

rsync [OPTION] [SRC] [USER@]HOST:DEST

Remote to Local

rsync [OPTION] [USER@]HOST:SRC [DEST]

Common options[OPTION] used with rsync commands

-v : verbose

-r : copies data recursively (but don’t preserve timestamps and permission while transferring data.

-a : archive mode, which allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships, and timestamps.

-z : compress file data.

-h : human-readable, output numbers in a human-readable format.

For more options, the following command can be used.

$ rsync -h

For example, to backup data from local to local(external hard drive), the following command is commonly used.

rsync -azv /home/username/projects /media/username/SPHardDrive/BackupFolder

Schedule backups

To enable scheduled backups, cron can be used for the rsync commands.

Conclusion

This is all how to copy, synchronize and backup files & directories. And I recommend the link to learn more about rsync.

Hope you enjoy that.

By Asahi



Laravelのファイルアップロード: 重複するファイル名 – 解決するための2つの方法

今日は、ファイルのアップロードについて、特に、同じファイル名でファイルをアップロードできるようにするとどうなるか、古いファイル名を上書きしてしまうか、それをいろいろとお話したいと思います。

例えば、デフォルトで登録フォームがあり、アバターがあり、誰かがavator.jpgというファイル名でファイルをアップロードしたとします。これは正常にアップロードされているのですが、開発者がよくやるのは、ClientOriginalNameが悪意のないものであることを信じてファイル名をアップロードすることです。
しかし、元のファイル名を保持したい場合は、それは大丈夫かもしれません。しかし、同じファイル名で登録した人がいて、そのファイルがstorage/app/public/avatorsにavator.jpgとしてアップロードされた場合、問題が発生することがあります。

そして、別のユーザーで登録しようとし、ユーザー情報を入力し、異なるパスからアバターをアップロードしますが、ファイル名は同じです。登録後、古いアバターはやみくもに上書きされ、サーバーから削除されることさえあります。というわけで、これは今問題になっています。どのようにコードでそれを解決するかは、いくつかの異なる方法があります。

ということで、今からこの方法をお話ししたいと思います。

1つ目はファイル名を変更する方法です。

if ($request->file('avatar')) {
            $fileName = pathinfo($request->file('avatar')->getClientOriginalName(), PATHINFO_FILENAME) . '-' . $user->id . '.' . $request->file('avatar')->getClientOriginalExtension();

            $request->file('avatar')->storePubliclyAs('avatars', $fileName, 'public');

            $user->update([
                'avatar' => $fileName ?? null,
            ]);
        }

アベータがある場合、拡張子なしのファイル名からファイルを作成し、ユーザ登録からuser_id、そしてオリジナルの拡張子からファイルを構築することになります。そして、そのファイルをファイル名と一緒にパブリックドライバに保存し、ユーザを更新します。

2つ目はサブフォルダを作成する方法です。

$request->file('avatar')->storePubliclyAs("avatars/{$user->id}", $request->file('avatar')->getClientOriginalName(), 'public');

publicのuser_idサブフォルダに元のファイル名で保存します。

結果一覧

はい。ということで今回は以上になります。

By Ami



DataTablesを使用したテーブル生成とサーバーサイド連携(4)

今回はDataTablesを使用したテーブル生成方法とサーバーサイド連携方法の連載Part4です。
前回の記事「DataTablesを使用したテーブル生成とサーバーサイド連携(3)」で発生した問題の原因と解決の方法について紹介いたします。

続きを読む

Comparisons between Ubuntu and Linux Mint

Today, I would like to share about comparisons between Ubuntu and Linux Mint Operating systems. Let’s take a look.

Ubuntu is the most famous Linux distribution. Its development started back in 2004. It is based on Debian distribution, which is why Ubuntu also uses the dpkg packaging system (And .deb package format) along with the apt packager manager.

Linux Mint, on the other hand, is based on Ubuntu. Its development started in 2008. Hence, Mint by extension is also based on Debian, and uses the same package manager and packaging system.

1. Distribution Goals

Ubuntu does not aim to be a simple Linux desktop distribution. Instead, Ubuntu is a general-purpose Linux distribution that can be used on servers, cloud, IoT and embedded devices.

Linux Mint, on the other hand, is nothing more than a desktop Linux distribution. There are no Linux Mint versions for servers or cloud or IoT… etc.

2. Software Manager

Ubuntu Software Center is slow while interacting with it. Of course, things have improved over the years but even with Ubuntu 20.04, on board, you will often notice it loading up slow or freezing when updating/installing an app. On the other hand, Linux Mint’s Software Manager is lighter and quicker.

3. User Interfaces

Ubuntu comes with the GNOME desktop environment. GNOME is an open-source desktop environment, which means that it’s a collection of programs associated with a GUI. The GNOME GUI has a dock on the left side where you can see all opened applications.

Mint comes with Cinnamon as a default desktop environment. Cinnamon is a Windows-like interface with a launcher, panel, and a system notification area on the bottom.

Ubuntu does support other desktop environments like Budgie, KDE, and Xfce. Mint only supports KDE and Xfce in addition to its default, Cinnamon.

4. Memory Usage

Desktop environments usually consume a lot of memory in order to run, which reduces the performance of the OS. Both Cinnamon and GNOME have their own perks but Cinnamon consumes significantly lesser memory than Ubuntu Desktop, making Mint the best distro for old PCs. So, the advantage of Mint is Cinnamon’s lower memory consumption as compared to GNOME.

5. Preinstalled Applications

Every Linux distribution comes with preinstalled applications like internet browsers, video players, image editors, and text editors. While Ubuntu offers more applications, their applications are difficult to search for, as you have to remember the exact name of the application. You can’t just guess the name or depend on browsing to find it.

Mint, on the other hand, only offers basic applications, but those applications are easy to find on their Windows-like menu.

This is all for now. Hope you enjoy that.

By Asahi



Mermaid diagrams in Github markdown

The only way to include images and figures in your Github Markdown file is to embed images or svgs. If you want to keep your diagrams updated, want to make changes everytime and create diagrams easily, you should take a look at Mermaid.

Mermaid is a JavaScript-based graphing and charting tool that takes Markdown-inspired text definitions and dynamically creates charts in your browser.

It supports a variety of common diagram types for software projects like flowcharts, UML, Git charts, user flow diagrams, Gantt charts.

For example, its syntax is like below.

```mermaid
  graph TD;
      A-->B;
      A-->C;
      B-->D;
      C-->D;
```
Credit: Github

The above code snippet will output as below.

rendered diagram example
Credit : Github

The result is a fast, easy-to-edit vector-based diagram where you need it in your document. Mermaid is becoming more and more popular among developers and have a rich community of contributors.

When we write a block of code marked as mermaid, it generates an iframe that takes the raw syntax of Mermaid and passes it to Mermaid.js, converting that code into a diagram in the local browser.

As a conculsion , it’s awesome and convient for developers who want to add diagrams on their github markdown. Thanks to the Knut Sveidqvist, creator of mermaid and you can also checkout the mermaid website here.

Yuuma




アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム